public interface MockitoRule
extends org.junit.rules.MethodRule
MockitoJUnitRunner
.
It requires JUnit at least 4.7.
This rule adds following behavior:
Mock
,
so that explicit usage of MockitoAnnotations.initMocks(Object)
is not necessary.
Mocks are initialized before each test method.
Mockito.validateMockitoUsage()
.
public class ExampleTest {
@Rule
public MockitoRule rule = MockitoJUnit.rule();
@Mock
private List list;
@Test
public void shouldDoSomething() {
list.add(100);
}
}