public class MockitoExtension
extends java.lang.Object
implements org.junit.jupiter.api.extension.TestInstancePostProcessor, org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallback
MockitoJUnitRunner.
Example usage:
@ExtendWith(MockitoExtension.class)
public class ExampleTest {
@Mock
private List list;
@Test
public void shouldDoSomething() {
list.add(100);
}
}
If you would like to configure the used strictness for the test class, use MockitoSettings.
@MockitoSettings(strictness = Strictness.STRICT_STUBS)
public class ExampleTest {
@Mock
private List list;
@Test
public void shouldDoSomething() {
list.add(100);
}
}
| Modifier and Type | Method and Description |
|---|---|
void |
afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
Callback that is invoked after each test has been invoked.
|
void |
beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
Callback that is invoked before each test is invoked.
|
void |
postProcessTestInstance(java.lang.Object testInstance,
org.junit.jupiter.api.extension.ExtensionContext context)
Callback for post-processing the supplied test instance.
|
public void postProcessTestInstance(java.lang.Object testInstance,
org.junit.jupiter.api.extension.ExtensionContext context)
Callback for post-processing the supplied test instance.
Note: the ExtensionContext supplied to a
TestInstancePostProcessor will always return an empty
Optional value from getTestInstance(). A TestInstancePostProcessor should therefore
only attempt to process the supplied testInstance.
postProcessTestInstance in interface org.junit.jupiter.api.extension.TestInstancePostProcessortestInstance - the instance to post-process; never nullcontext - the current extension context; never nullpublic void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
beforeEach in interface org.junit.jupiter.api.extension.BeforeEachCallbackcontext - the current extension context; never nullpublic void afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
afterEach in interface org.junit.jupiter.api.extension.AfterEachCallbackcontext - the current extension context; never null