【发布时间】:2013-07-30 19:39:18
【问题描述】:
我有一个处理异常的方法:
public boolean exampleMethod(){
try{
Integer temp=null;
temp.equals(null);
return
}catch(Exception e){
e.printStackTrace();
}
}
我想测试一下
public void test_exampleMethod(){}
我试过了
@Rule
public ExpectedException expectedException=ExpectedException.none();
public void test_exampleMethod(){
expectedException.expect(JsonParseException.class);
exampleMethod();
}
但这不起作用,因为异常是在内部处理的。
我也试过了
@Test(expected=JsonParseException.class)
但同样的问题...处理了异常
我知道我能做到
assertTrue(if(exampleMethod()))
但它仍会将堆栈跟踪打印到日志中。我更喜欢干净的日志...有什么建议吗?
【问题讨论】:
-
你的例子不完整,你需要在你的方法的最后一个return语句