0

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?

Pablo
  • 55
  • 8

1 Answers1

0

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>
Stefan Birkner
  • 24,059
  • 12
  • 57
  • 72