Skip to content

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

@sbrannen

Description

@sbrannen

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions