chevron-thin-right chevron-thin-left brand cancel-circle search youtube-icon google-plus-icon linkedin-icon facebook-icon twitter-icon toolbox download check linkedin phone twitter-old google-plus facebook profile-male chat calendar profile-male
0 votes
Hi,
I'm using following attributes for each nunit test

[Test, VerifyMocks, ClearMocks]

It looks like that the result of the tests depend on the sequence of the attributes, e.g. if clearMocks is done before VerifyMocks, VerifyMocks will never report an error....

For some reasons, it looks like that on some machines the order is like in the statement, meaning VerifyMocks is done before ClearMocks. But on some machines the order is different and some tests pass that should not.

Is this a real problem? Should I use the TearDown method to Clear the mocks instead of using the attribute?

Thanks
asked by Step (3.4k points)

1 Answer

0 votes
Hi,

It looks like that the result of the tests depend on the sequence of the attributes, e.g. if clearMocks is done before VerifyMocks, VerifyMocks will never report an error....

Thats true, clearing the mocks before the verify will make the test pass since there is nothing to verify.


For some reasons, it looks like that on some machines the order is like in the statement, meaning VerifyMocks is done before ClearMocks. But on some machines the order is different and some tests pass that should not.

Again thats possible since the CLR does not guarantee the ordering of the attributes.


Is this a real problem? Should I use the TearDown method to Clear the mocks instead of using the attribute?

Actually no. You can do one of the following two:
1) You can remove the ClearMocks on all tests which has VerifyMocks.The Verify operation do a clear at its end.
2) you can put the ClearMocks on the test classes and the VerifyMocks on the test methods. If you'll do that the clearing will always be done after the verification.
answered by lior (13.2k points)
...