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

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”, 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 ?

1 Like

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.

1 Like

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