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.

Introduce MockitoExtension for JUnit Jupiter (a.k.a. JUnit 5)

See original GitHub issue

New 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 MockitoExtension for JUnit Jupiter to replace the proof of concept from the JUnit team.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:36
  • Comments:64 (44 by maintainers)

github_iconTop GitHub Comments

13reactions
MarkNBroadheadcommented, Jul 17, 2018

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

7reactions
TimvdLippecommented, Feb 17, 2018

The intent now is to ship junit5 support in a separate artifact with mockito 2

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mockito and JUnit 5 - Using ExtendWith - Baeldung
First, we'll show how to create an extension that automatically creates mock objects for any class attribute or method parameter annotated with @Mock....
Read more >
JUnit 5 User Guide
JUnit Jupiter is the combination of the programming model and extension model for writing tests and extensions in JUnit 5.
Read more >
How to use Mockito with JUnit5 - java - Stack Overflow
JUnit 5 has a powerful extension model and Mockito recently published one under the group ... MockitoExtension; import org.junit.jupiter.api.extension.
Read more >
JUnit 5 tutorial, part 1: Unit testing with JUnit 5, Mockito, and ...
The MockitoExtension looks at the test class, finds member variables annotated with the @Mock annotation, and creates a mock implementation of ...
Read more >
What the Heck Is the SpringExtension Used For? - rieckpil
Understand what the JUnit Jupiter SpringExtension (JUnit 5) is used for and when to register it for testing Spring Boot applications.
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