![](/img/trans.png)
[英]How to create custom JUnit4 assertions that don't show in the Failure Trace
[英]How to get failure trace with Junit4
在Junit测试中,我通常使用“ AssertEquals”,并且当测试失败时,该跟踪会正确显示在JUnit / eclipse的失败跟踪中,我想知道如何获取这些跟踪以在文件中显示它?
@Test
public void testButtons() {
SelectionButton().ButtonFile();
assertEquals("selected button should be edit",FILE.EDIT,File.getSelectedItem);
}
如何打印/重定向文件中的断言失败跟踪? 谢谢
JUnit的assertEquals
方法抛出一个AssertionError
而没有错误消息。 如果要记录有关失败的更多信息,则必须捕获AssertionError
如下所示:
try{
assertEquals(true, true);
}catch (AssertionError ex) {
//Do Something
throw(ex);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.