I just need to know
1) when I call when()
in Mockito, it is actually executing the mockedObject method behaviour or not?
2) what If when I return a wrong value in when().thenReturn()
like below. The test case will be "false" or will it return 50 instead of 30?
when(mockedObject.add(10,20)).thenReturn(50);
3) why should I need to use thenReturn()
mandatory, even when the mocked object method is void? ( it's giving error when I didn't use thenReturn()
.
adds functionality to a mock object using the when() method.
@Test
public void testAdd(){
when(mockedObject.add(20.0,30.0)).thenReturn(50.00);
}
4) If I call
verify(mockedObject,times(1)).add(20.0, 30.0);
It checks that the methods are called on a mocked object or not with the same parameter and check the call to the method as only 1 time, right? So can I use when() to add a functionality to the mocked object method without using verify() or it actually requires to invoke verify() after calling when() method