org.mockito.junit
public interface MockitoRule extends org.junit.rules.MethodRule
MockitoHint
).
The JUnit rule can be used instead of MockitoJUnitRunner
.
It requires JUnit at least 4.7.
This rule adds following behavior:
silent()
.
However, we would really like to know why do you wish to silence the warnings!
See also MockitoHint
.
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);
}
}
Modifier and Type | Method and Description |
---|---|
MockitoRule |
silent()
Rule will not report stubbing warnings during test execution.
|
MockitoRule silent()
Please give us feedback about the stubbing warnings of JUnit rules.
It's a new feature of Mockito 2.1.0. It aims to help debugging tests.
We want to make sure the feature is useful.
We would really like to know why do you wish to silence the warnings!
See also MockitoHint
.
Example:
public class ExampleTest {
@Rule
public MockitoRule rule = MockitoJUnit.rule().silent();
}