将测试数据注入Junit报告以获取失败的测试(使用的是failafe插件)

时间:2014-12-02 13:58:11

标签: junit maven-failsafe-plugin

我在列表中使用failafe和Junit进行了几个测试用例,如下所示:

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

我希望报告类似:

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

而不仅仅是:

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

有没有办法用Junit或其他框架做到这一点?

1 个答案:

答案 0 :(得分:0)

您可以向断言添加消息:

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

这会创建以下报告:

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