例如。
try {
// Some code
}
catch (IOException e) {
throw new CustomDefineException(e);
}我想为catch块编写mockito覆盖语句。如何做到这一点?我是mockito框架的新手。
发布于 2020-08-28 15:21:58
您可以编写测试用例,使代码真正抛出异常。控件将转到Catch块,您的覆盖率将会增加。
为了让测试用例通过,您可以编写期望得到异常的测试用例,如下所示
@Test(expected = CustomDefineException.class)
public void shouldThrowCustomDefineExceptionWhenWrongParameterIsSupplied() {
// Your Logic to create Exception
}在测试方法的顶部。
https://stackoverflow.com/questions/63562851
复制相似问题