在我的Junit测试中,我经常使用“AssertEquals”,当测试失败时,跟踪在JUnit / eclipse的Failure trace中正确显示 我想知道如何将这些跟踪显示在文件中?
@Test
public void testButtons() {
SelectionButton().ButtonFile();
assertEquals("selected button should be edit",FILE.EDIT,File.getSelectedItem);
}
如何在文件中打印/重定向断言失败跟踪? 感谢
答案 0 :(得分:2)
JUnit的assertEquals
方法抛出AssertionError
时没有错误消息。如果您想记录有关失败的更多信息,您必须抓住AssertionError
,如:
try{
assertEquals(true, true);
}catch (AssertionError ex) {
//Do Something
throw(ex);
}