Package org.mockito.testng
Class MockitoTestNGListener
- java.lang.Object
-
- org.mockito.testng.MockitoTestNGListener
-
- All Implemented Interfaces:
org.testng.IInvokedMethodListener,org.testng.ITestNGListener
public class MockitoTestNGListener extends java.lang.Object implements org.testng.IInvokedMethodListenerMockito TestNG Listener, this listener initializes mocks and handles strict stubbing, it is similar to JUnit
MockitoJUnitRunner,MockitoRule,MockitoExtensionand adds the following behavior to your test:-
Before any test method or a configuration method @BeforeMethod
MockitoSession is started by:
See javadocMockito.mockitoSession() .initMocks(testInstance) .strictness(Strictness.STRICT_STUBS) .startMocking()MockitoSession -
After each test method
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
MockitoSessionis started withStrictness.STRICT_STUBS. You can change this behavior by addingMockitoSettingsto your test class.@Listeners(MockitoTestNGListener.class) @MockitoSettings(strictness = Strictness.WARN) public class ExampleTest { ... }MockitoTestNGListenernot working with parallel tests, more information https://github.com/mockito/mockito-testng/issues/20
-
-
Constructor Summary
Constructors Constructor Description MockitoTestNGListener()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterInvocation(org.testng.IInvokedMethod method, org.testng.ITestResult testResult)voidbeforeInvocation(org.testng.IInvokedMethod method, org.testng.ITestResult testResult)protected booleanhasMockitoTestNGListener(org.testng.ITestResult testResult)
-
-
-
Method Detail
-
beforeInvocation
public void beforeInvocation(org.testng.IInvokedMethod method, org.testng.ITestResult testResult)- Specified by:
beforeInvocationin interfaceorg.testng.IInvokedMethodListener
-
afterInvocation
public void afterInvocation(org.testng.IInvokedMethod method, org.testng.ITestResult testResult)- Specified by:
afterInvocationin interfaceorg.testng.IInvokedMethodListener
-
hasMockitoTestNGListener
protected boolean hasMockitoTestNGListener(org.testng.ITestResult testResult)
-
-