我知道一个简单的方法是这样的:
try {
//perform something you expect no exceptions
} catch (Exception e) {
Assume.assumeTrue(e.getErrorMessage().equals("Expected Exception");
}
Run Code Online (Sandbox Code Playgroud)
有什么其他更优雅的方法可以让我的JUnit在抛出特定异常时传递,并且当Exception.thrown 完全没有抛出异常时?