开发者

How to get failure trace with Junit4

开发者 https://www.devze.com 2023-01-19 08:36 出处:网络
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

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

精彩评论

暂无评论...
验证码 换一张
取 消