相关疑难解决方法(0)

如何测试没有抛出异常?

我知道一种方法是:

@Test
public void foo(){
   try{
      //execute code that you expect not to throw Exceptions.
   }
   catch(Exception e){
      fail("Should not have thrown any exception");
   }
}
Run Code Online (Sandbox Code Playgroud)

有没有更清洁的方法来做到这一点.(可能使用Junit的@Rule?)

java junit unit-testing exception-handling junit4

206
推荐指数
10
解决办法
18万
查看次数

标签 统计

exception-handling ×1

java ×1

junit ×1

junit4 ×1

unit-testing ×1