Question: Will parallel running mess up invocation counts?
I have a set of tests and they currently run sequentially but what I found was this:
- Test 1 checks "did I call X() exactly once" and passes
- Test 2 checks "did I call X() exactly once" and fails (the count is 2)
- Test 3 checks "did I call X() exactly once" and fails (the count is 3)
The fix was simply to ensure that the invocation count get cleared after each test using ...Invocations.Clear().
But now colleagues want to run the tests in parallel and I'm wondering will each parallel instance get its own invocation counts storage or are the parallel instances going to access a common set of counts with chaos being the result?
You shouldn't reuse mocks across tests. Setups should be per test-class instance (i.e. each test gets a unique instance of the test class), like xunit does with ctor/IDisposable. Therefore, there would be no way for two tests to run in parallel against the same mock instance. That would be a general guideline, but I'm not sure about the particulars of your setup and how you intend to parallelize things.
Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.
This issue will now be closed since it has been labeled 'stale' without activity for 30 days.
