如果JUnit测试返回预期的异常,是否有可能成功?
你能告诉我如何通过简化的例子来实现这样的测试吗?
非常感谢.
我试图覆盖一个方法,抛出异常:
class A {
public doSomething(){
// some of logic
}
}
class B extends A {
public doSomething() throws MyCustomizedException {
try {
// some of logic
} catch(ExceptionX ex ) {
throw new MyCustomizedException(" Some info ", ex);
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个编译时错误:
Exception MyCustomizedException is not compatible with throws clause in A
Run Code Online (Sandbox Code Playgroud)
这两个限制是:
我该怎样摆脱异常?
非常感谢.