Mock
1. Initialising Mock Objects - Mockito
https://stackoverflow.com/questions/15494926/initialising-mock-objects-mockito
1). MockitoAnnotations
public class SampleBaseTestCase{
@Before public void initMocks(){
MockiotAnnotations.initMocks(this);
}
}
2). RunWith
@RunWith(MockitoJUnitRunner.class)
3).
mock(xxx.class);
2. @Mock VS @InjectMocks
@Mock creates a mock. @InjectMocks creates an instance of the class and injects the mocks that are created with the @Mock(or @Spy) annotations into this instance. Note that you must use @RunWith(MockitoJUnitRunner.class) or Mockito.initMocks(this) to initialize these mocks and inject them.
Mockito.when(mockclass.methof(Mockito.any())).thenReturn(true);
Last updated
Was this helpful?