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);
}
}
Constructor and Description |
---|
MockitoExtension() |
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.TestInstancePostProcessor
testInstance
- the instance to post-process; never null
context
- the current extension context; never null
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
beforeEach
in interface org.junit.jupiter.api.extension.BeforeEachCallback
context
- the current extension context; never null
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
afterEach
in interface org.junit.jupiter.api.extension.AfterEachCallback
context
- the current extension context; never null