withObjectMocked is not threadsafe
See original GitHub issueHi! It seems withObjectMocked
may cause unexpected failures when tests are executing in parallel. According to implementation, it uses reflection to set an internal state of a singleton which may lead to unexpected behavior when another test runs in a different thread and tries to interact with that scala object.
This can lead to the following exceptions:
org.mockito.exceptions.verification.NoInteractionsWanted: No interactions wanted here
or
org.mockito.exceptions.misusing.UnexpectedInvocationException: Unexpected invocations found
or
org.mockito.exceptions.verification.SmartNullPointerException: You have a NullPointerException here
Any help or workaround will be appreciated! Thanks in advance.
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (7 by maintainers)
Top Results From Across the Web
MockHandlerImpl: Not thread safe reportOngoingStubbing
I've written a test to reproduce the issue. Since it's about a race condition to reproduce it u probably require to run the...
Read more >Mocked methods created within `withObjectMocked` not ...
My goal is to mock the doit function below. It should not be called during tests, so for this demonstration it simply throws...
Read more >org.scalatest.mock.MockitoSugar Scala Example
This page shows Scala examples of org.scalatest.mock.MockitoSugar.
Read more >User Guide - FAQ - ScalaMock
Yes - ScalaMock is thread-safe and mocks can be used in a multi-threaded ... This is not supported, as mocks generated with macros...
Read more >mockito-scala
simpleMethod shouldBe "not mocked!" } } As you can see, the effect of the mocking is only available inside the code block passed...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
booo, it worked in my machine 😅
@bbonanno that looks great! 👍 Looking forward to the release 😉