Could HippoMocks be used within concurrent testcases just like this:
synchronized startup phase
- create mock
- register expectations etc.
parallel testing phase
- call methods on the mock
synchronized teardown phase
- verify the mock
I did not find an explicit statement regarding this issue. Here and there it is mentioned, that mocking non-virtual methods would destroy the possibility for thread-safety (HippoMocks: is it possible to mock non-virtual methods?) or that thread-safety could be added quite easily (unfortunately without actually revealing how). GoogleMock answers this question very clearly (https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md#using-google-mock-and-threads), such an information would be helpful here, too.
No, HippoMocks is not designed to be thread safe.
However, if you follow some simple rules you should be able to use mocks in a multithreaded environment:
UPDATE: Okay, I did it. I wrote a small test for multithreading
The result is, that it works fine. Now I made it a little bit harder and replaced the second OnCall by the following:
Here you will get crashes randomly (just play around with the THREAD_ITERATIONS counter). The reason is, that the matched expectations are somehow counted in the Mockrepository.
Doing the setup concurently crashes, as expected.