Package org.mockito.junit
Interface MockitoRule
-
- All Superinterfaces:
org.junit.rules.MethodRule
- All Known Implementing Classes:
MockitoJUnitRule
public interface MockitoRule extends org.junit.rules.MethodRule
The JUnit rule can be used instead ofMockitoJUnitRunner
. It requires JUnit at least 4.7. This rule adds following behavior:-
Initializes mocks annotated with
Mock
, so that explicit usage ofMockitoAnnotations.initMocks(Object)
is not necessary. Mocks are initialized before each test method. -
validates framework usage after each test method. See javadoc for
Mockito.validateMockitoUsage()
.
public class ExampleTest { @Rule public MockitoRule rule = MockitoJUnit.rule(); @Mock private List list; @Test public void shouldDoSomething() { list.add(100); } }
- Since:
- 1.10.17