For eg.
try {
// Some code
}
catch (IOException e) {
throw new CustomDefineException(e);
}
I want to write mockito coverage statement for the catch block. How can that be done? I'm new on mockito framework.
For eg.
try {
// Some code
}
catch (IOException e) {
throw new CustomDefineException(e);
}
I want to write mockito coverage statement for the catch block. How can that be done? I'm new on mockito framework.
So basically as per Joni, we can only test the catch block, when there is actually an exception that is occurring, till then it cannot be tested.
You can write the test cases that actually make the code to throw exception. The control would go to the Catch Block and your coverage would increase.
For the test case to pass you can write the test case that would expect to get exception like
@Test(expected = CustomDefineException.class)
public void shouldThrowCustomDefineExceptionWhenWrongParameterIsSupplied() {
// Your Logic to create Exception
}
on the top of the test Method.