Inject test data to Junit reports for failed tests (failsafe plugin used)

70 views Asked by At

I have several tests cases in a list using failsafe and Junit as per below:

    @Test
    public void testResults() {
        for (TestCase test : TestCaseList) {
            int result = test.getActualResult();
            int expected = test.getExpectedResult();
                if (result != expected) {
                    System.out.println("Failed test " + test.getTestInfo());
                }
                assertEquals(result, expected);
        }
    }

I want the report something like :

Failed test <test description here>
java.lang.AssertionError: 
Expected: is <4>
     but: was <2>

Instead of just:

java.lang.AssertionError: 
Expected: is <4>
     but: was <2>

Is there a way to do that with Junit or other framework?

1

There are 1 answers

0
Stefan Birkner On BEST ANSWER

You can add a message to the assert:

assertEquals(test.getTestInfo(), result, expected);

This creates the following report:

java.lang.AssertionError: <test description here>
  Expected: is <4>
       but: was <2>