-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
JUnit 5 has the ability to "inject" parameters into test methods via an extensible ParameterResolver interface. The JUnit 5 users guide provides an example that shows how such a ParameterResolver can supply mock objects as test parameters as follows (shamelessly copied from https://junit.org/junit5/docs/current/user-guide/#writing-tests-dependency-injection):
@ExtendWith(MockitoExtension.class)
class MyMockitoTest {
@BeforeEach
void init(@Mock Person person) {
when(person.getName()).thenReturn("Dilbert");
}
@Test
void simpleTestWithInjectedMock(@Mock Person person) {
assertEquals("Dilbert", person.getName());
}
}
The prototype MockitoExtension provided in the JUnit 5 samples project shows a simple implementation of the required supportsParameter() and resolveParameter() methods. (See: https://github.com/junit-team/junit5-samples/blob/r5.1.0/junit5-mockito-extension/src/main/java/com/example/mockito/MockitoExtension.java)
[ ] Add the ability to inject mock objects into test method parameters to the official MockitoExtension. References #445