简体   繁体   中英

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?

@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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM