Mocking is sometimes not applied when running a multi-class testsuite

Skip to first unread message

Anton Oellerer

Jan 20, 2023, 10:53:41 AMJan 20
to mockito
I am testing a service which heavily relies on project reactor.
For many tests I am mocking the return value of the component responsible for API calls. The tests are split over multiple files.
When I run the tests of one file, they are green, but when I execute all of the test files at once, some tests fail, with the error message indicating that the mocking did not succeed (Either the injected component returned `null`, or the implementation of the actual component is invoked).
In the logs, there is no information about the mocking failing.
I attached a small code example.
Do you know what the reason is/might be for the tests failing?
For me the issue seems like a race condition, but I don't know where and how this might happen, and how I can check and fix this.
Best regards
Anton Oellerer

Anton Oellerer

Mar 30, 2023, 8:58:44 AMMar 30
to mockito

I fixed this by annotating each class with `@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)`

Reply all
Reply to author
0 new messages