[英]How to get failure trace with Junit4
in my Junit test, I use usually "AssertEquals" and when the test fails, the trace is properly displayed in the Failure trace of JUnit/eclipse I would like to know how to get these trace to show it in a file? 在Junit测试中,我通常使用“ AssertEquals”,并且当测试失败时,该跟踪会正确显示在JUnit / eclipse的失败跟踪中,我想知道如何获取这些跟踪以在文件中显示它?
@Test
public void testButtons() {
SelectionButton().ButtonFile();
assertEquals("selected button should be edit",FILE.EDIT,File.getSelectedItem);
}
how could I print/redirect the assert failure trace in a file ? 如何打印/重定向文件中的断言失败跟踪? thanks 谢谢
The assertEquals
method of JUnit throws an AssertionError
without a message on error. JUnit的assertEquals
方法抛出一个AssertionError
而没有错误消息。 If you want to log more information on the failure you will have to catch the AssertionError
like in: 如果要记录有关失败的更多信息,则必须捕获AssertionError
如下所示:
try{
assertEquals(true, true);
}catch (AssertionError ex) {
//Do Something
throw(ex);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.