Mockito commonly used methods:
Method name | description |
---|---|
Mockito.mock(classToMock) | Mock objects |
Mockito.verify(mock) | Verify whether the conduct occurred |
Mockito.when(methodCall).thenReturn(value1).thenReturn(value2) | The first returns value1 when triggered, the n-th return value2 |
Mockito.doThrow(toBeThrown).when(mock).[method] | Analog thrown. |
Mockito.mock(classToMock,defaultAnswer) | Use the default Answer mock objects |
Mockito.when(methodCall).thenReturn(value) | Parameter matching |
Mockito.doReturn(toBeReturned).when(mock).[method] | Matching parameters (do not direct determination) |
Mockito.when(methodCall).thenAnswer(answer)) | Callback interface is expected to generate expectations |
Mockito.doAnswer(answer).when(methodCall).[method] | Callback interface is expected to generate a desired value (do not direct determination) |
Mockito.spy(Object) | With real spy monitor object, set the behavior of real objects |
Mockito.doNothing().when(mock).[method] | Without any return |
Mockito.doCallRealMethod().when(mock).[method] //等价于Mockito.when(mock.[method]).thenCallRealMethod(); | Call the real way |
reset(mock) | Reset mock |