Replies: 1 comment
-
I think you may have addressed this to the wrong people. While this is the JUnit 5 discussion board, the Mockito extension is made by the Mockito team and they have their own discussion boards over at https://github.com/mockito/mockito/discussions. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Lets assume we have class like this and we want to cover it with unit tests:
Where its dependencies look like this:
In most common case unit test for this class will look like this:
Using
MockitoExtension
allow you to decrease amount of boiler plate code to some degree:This looks much better but you still need to cover all mocks and/or spies with
Mockito.verifyNoMoreInteractions
. My suggestion is to extend existing or implement additional Jupiter extension for Mockito which will handle mentioned verification. So same test will look like this:Where extension implementation may look like this (actually it should use mock api to extract mocks from ExtensionContext but i'm not aware if there is such functionality for now, so i wrote some reflection code to extract mocks from the test class itself) :
What this code does: it picks up test instance class from the ExtensionContext, extract all declared fields which identified as mocks or spies and run
verify no more interactions
for those fields.Beta Was this translation helpful? Give feedback.
All reactions