in my Junit test, I use usually "AssertEquals" and when the test fails, the trace is properly displayed in the Failure trace o开发者_JAVA技巧f JUnit/eclipse I would like to know how to get these trace to show it in a file?
@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. If you want to log more information on the failure you will have to catch the AssertionError
like in:
try{
assertEquals(true, true);
}catch (AssertionError ex) {
//Do Something
throw(ex);
}
精彩评论