public class MockitoTestNGListener
extends java.lang.Object
implements org.testng.IInvokedMethodListener
Mockito TestNG Listener, this listener initializes mocks and handles strict stubbing, it is similar to JUnit
MockitoJUnitRunner
, MockitoRule
, MockitoExtension
and adds
the following behavior to your test:
Mockito.mockitoSession()
.initMocks(testInstance)
.strictness(Strictness.STRICT_STUBS)
.startMocking()
See javadoc MockitoSession
MockitoSession.finishMocking()
is called.
Example usage:
@Listeners(MockitoTestNGListener.class)
public class ExampleTest {
@Mock
private List list;
@Test
public void shouldDoSomething() {
list.add(100);
}
}
By default MockitoSession
is started with Strictness.STRICT_STUBS
.
You can change this behavior by adding MockitoSettings
to your test class.
@Listeners(MockitoTestNGListener.class)
@MockitoSettings(strictness = Strictness.WARN)
public class ExampleTest {
...
}
MockitoTestNGListener
not working with parallel tests,
more information https://github.com/mockito/mockito-testng/issues/20
Constructor and Description |
---|
MockitoTestNGListener() |
Modifier and Type | Method and Description |
---|---|
void |
afterInvocation(org.testng.IInvokedMethod method,
org.testng.ITestResult testResult) |
void |
beforeInvocation(org.testng.IInvokedMethod method,
org.testng.ITestResult testResult) |
protected boolean |
hasMockitoTestNGListener(org.testng.ITestResult testResult) |
public void beforeInvocation(org.testng.IInvokedMethod method, org.testng.ITestResult testResult)
beforeInvocation
in interface org.testng.IInvokedMethodListener
public void afterInvocation(org.testng.IInvokedMethod method, org.testng.ITestResult testResult)
afterInvocation
in interface org.testng.IInvokedMethodListener
protected boolean hasMockitoTestNGListener(org.testng.ITestResult testResult)