How make JUnit print assertion results

前端 未结 4 861
说谎
说谎 2021-02-01 03:48

How can I get the results of my JUnit assertions to be printed [to standard output]?

I have some tests like this:

@Test
public void test01()
{
    Position         


        
4条回答
  •  滥情空心
    2021-02-01 04:05

    First, you have two issues not one. When an assertion fails, an AssertionError exception is thrown. This prevents any assertion past this point from being checked. To address this you need to use an ErrorCollector.

    Second, I do not believe there is any way built in to JUnit to do this. However, you could implement your own methods that wrap the assertions:

    public static void assertNotNull(String description, Object object){
         try{
              Assert.assertNotNull(description, object);
              System.out.println(description + " - passed");
         }catch(AssertionError e){
              System.out.println(description + " - failed");
    
            throw e;
         }
    }
    

提交回复
热议问题