# \[unit tests\] do you use mock objects with plausible values VS mocks with random fields?

**URL:** <https://forum.golangbridge.org/t/unit-tests-do-you-use-mock-objects-with-plausible-values-vs-mocks-with-random-fields/20455>\
**Category:** Getting Help\
**Created:** [September 3, 2020, 8:45pm UTC](https://forum.golangbridge.org/t/unit-tests-do-you-use-mock-objects-with-plausible-values-vs-mocks-with-random-fields/20455 "2020-09-03T20:45:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JOhn\_Stuart](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/john_stuart/32/5444_2.png) [@JOhn\_Stuart](https://forum.golangbridge.org/u/JOhn_Stuart)\
**Post date:** [September 3, 2020, 8:45pm UTC](https://forum.golangbridge.org/t/unit-tests-do-you-use-mock-objects-with-plausible-values-vs-mocks-with-random-fields/20455/1 "2020-09-03T20:45:30Z")

</div>

Testing the save operation for a User, my mockUser is something like this:

```
mock := models.User{
    name: "a",
    email: "b",
    comment: "c",
    ID: 1,
    role: 2,
}

```

Is this better to creating a mock user with an actual plausible name “John Doe”, a plausible email “[jonhdoe@yahoo.com](mailto:jonhdoe@yahoo.com)”, a plausible ID (345), etc.

I like my non plausible user because it seems that it removes some bias and reminds, to any person looking at that test, that these fields are just strings or numbers which can have any value and we must accomodate for strange input.

On the other hand, a plausible user can make the test prettier for a human reader ? What do you think, and which version do you use for production code ?

---

<div class="post-metadata">

**Author:** ![lutzhorn](https://forum.golangbridge.org/user_avatar/forum.golangbridge.org/lutzhorn/32/8119_2.png) [@lutzhorn](https://forum.golangbridge.org/u/lutzhorn)\
**Post date:** [September 4, 2020, 9:20am UTC](https://forum.golangbridge.org/t/unit-tests-do-you-use-mock-objects-with-plausible-values-vs-mocks-with-random-fields/20455/2 "2020-09-04T09:20:06Z")

</div>

Is it important to inform the reader that a string can have any value not just one that looks like a real name? I don’t think so. Use test data that tells the reader about why it is used, `John Doe` does this while `a` does not.

If you code _does_ enforce restrictions on values, write tests for them.

---

<div class="post-metadata">

**Author:** ![system](https://forum.golangbridge.org/uploads/default/original/2X/5/5ad234f7c3dbc68b6cc72d338ce4f2973d9fd81c.png) [@system](https://forum.golangbridge.org/u/system)\
**Post date:** [December 3, 2020, 9:20am UTC](https://forum.golangbridge.org/t/unit-tests-do-you-use-mock-objects-with-plausible-values-vs-mocks-with-random-fields/20455/3 "2020-12-03T09:20:10Z")

</div>

Closed on December 3, 2020, 9:20am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
