Skip to content

Unable to verify Mockito mock during a @MicronautTest testing #9957

Closed Answered by nedelva
nedelva asked this question in Q&A
Discussion options

You must be logged in to vote

Only after posting this question I realized the silly mistake I had made (as often happens 😞).

The reason for test failure was that during testing two instances of SomeServiceClient were created: one used by CachedMessageSource and another one was created and injected in the test class CachedMessageSourceTest (field someServiceClient).

The fix is trivial (once you know the cause of failure): the factory method MocksFactory.someServiceClient() needs to be annotated with @Singleton so that the same (mock) instance is used in all the injection points.

D'oh!

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by nedelva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant