Friday, September 26, 2014

To verify a Method is called or not in JUNIT which is running by MockitoJUnitRunner

We can verify a method its called or not?

This is the way to verify:

Mockito.verify(vaBuildRequestDao).create(Mockito.any(VaBuildRequest.class));

Above verify meaning we should expect a create method be called on VaBuildRequestDao.


Mockito.verify(vaBuildRequestDao,Mockito.times(2)).create(Mockito.any(VaBuildRequest.class));

Above verify meaning we are expecting the create method is called 2 times on VaBuildRequestDao .If it wont call the test case will be failed.

No comments: