java - Handle Exception with Mockito -
I am using mokita in my unit test. I have a method
public status getResponse (request requset) throws DataException {} DataException My definition is that the exception Inherited from the class.
In the case of my test
static {when (process.getResponse (any (Request.class))). Then return (new situation ("success")); } This returns an error, unchecked exception: DataException
to handle Mockito The method is to add this problem to your test method:
@Test (expected = DataException.class)
or use it:
then (caught exception ()). isInstanceOf (DataException.class); There is no way other than trying-hold for a static-block.
One way to change the runtime exception to DataException.
Comments
Post a Comment