Introduce MockitoExtension for JUnit Jupiter (a.k.a. JUnit 5)
See original GitHub issueNew Features in JUnit 5
The JUnit Jupiter extension model in JUnit 5 introduces support for constructor and method parameter resolution (i.e., dependency injection).
Specifically, third parties can implement the ParameterResolver extension API to inject dependencies, mocks, etc. into constructors and methods. In addition, the TestInstancePostProcessor extension API can be implemented to post-process a test instance (e.g., to perform field injection).
Status Quo
Mockito supports field injection for mocks via the @Mock annotation. In addition, #438 allows @Mock to be declared on parameters for constructors and methods which makes @Mock support an ideal candidate for both the TestInstancePostProcessor and ParameterResolver extension APIs in JUnit Jupiter. In fact, the JUnit Team has already developed a proof of concept: see the MockitoExtension in the junit5-mockito-extension sample project.
Deliverables
- Introduce an official
MockitoExtensionfor JUnit Jupiter to replace the proof of concept from the JUnit team.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:36
- Comments:64 (44 by maintainers)

Top Related StackOverflow Question
Since this is one of the top Google results for trying to get this working, and I’ll likely Google it again, I’d like to add that this is in the mockito-junit-jupiter project. Maven Central link mockito-junit-jupiter
The intent now is to ship junit5 support in a separate artifact with mockito 2