question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

withObjectMocked is not threadsafe

See original GitHub issue

Hi! 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:closed
  • Created 3 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
bbonannocommented, Nov 9, 2020

booo, it worked in my machine 😅

0reactions
oleksii-supruncommented, Nov 10, 2020

@bbonanno that looks great! 👍 Looking forward to the release 😉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found