Mockito is junit testing framework , which actually mock the behaviour of methods.
It simplify the development of tests of classes with dependencies.
I hope you are familiar with junit .
A mock object is dummy object of classes and interface.
How to use when-then and when-thenThrow
When we want mock the object which returns any objects or any datatype values
We can use this when thenReturn.
Example:
If in certain scenario we want to test exception block then we can use when-thenThrow.
Example:
If we have any parameters to add in it we can do .
How to use doReturn when and doThrow when
For this we have to spy the classes. It does patial mocking means
Mock only specific methods while keeping real behaviour for the test.
It will actually call real implemenation in controlled manner.
We can do spy in this way
Example:
Thank You
Amarnath Mali
Helical IT Solutions
Best Open Source Business Intelligence Software Helical Insight is Here