[TOC]
Generating a kind of virtual object for verifying the method reacting output which fits our expecting.
-
Verifying the using status of a assignment object's method and how many times was executed, and what's the parameters, etc.
-
Assigning the action of a object's method or specific return value, or specific executing action, etc.
There are three ways for activing the Mockito annotations such as @Mock, @Spy, @InjectMocks, etc.
- Annotating the JUnit test class.
@RunWith(MockitoJUnitRunner.class)
public class TestClass {
}- Invoking it in the @Before method.
public class TestClass {
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
}
}- Using a Mockito JUnit rule.
public class TheTest {
@Rule public MockitoRule mockito = MockitoJUnit.rule();
}