Is there a way to force Maven Surefire or JUnit to indicate the name of the failing test class when executed from a Test Suite?

纵然是瞬间 提交于 2019-12-12 10:50:15

问题


My question: Is there a way to force Maven Surefire (or JUnit?) to indicate the name of the failing test class when this class has been executed from a Test Suite?

Now, the long story.

Imagine you have a JUnit test suite that launches two JUnit tests.

Examples of test classes:

public class TestOne {

    @Test
    public void foo() {
        assertTrue(false);
    }

    @Test
    public void bar() {
        assertTrue(false);
    }

}

@UnitTest
public class TestTwo {

    @Test
    public void foo() {
        assertFalse(true);
    }

}

and the test suite:

@RunWith(Suite.class)
@SuiteClasses(value = { TestOne.class, TestTwo.class })
public class MySuite {

}

Now, if I run the test suite (mvn test -Dtest=MySuite), I will have the following errors:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running caf.opm.preclosing.junit.MySuite
Tests run: 3, Failures: 3, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec <<< FAILURE!

Results :

Failed tests:
  foo(my.project.junit.TestOne)
  bar(my.project.junit.TestOne)
  foo(my.project.junit.TestTwo)

Tests run: 3, Failures: 3, Errors: 0, Skipped: 0

So reading these lines, I can easily detect which classes and tests are failing.

However, in target/surefire-reports/ directory, I have only one file, MySuite.txt where the three tests are failing. One of the consequences of such situation is that my Hudson build will show me the following information:

All Failed Tests
Test Name       Duration    Age   
>>> my.project.junit.MySuite.foo    0.0 1
>>> my.project.junit.MySuite.bar    0.0 1
>>> my.project.junit.MySuite.foo    0.0 1

As you can see, it becomes harder to identify the failing tests, and for example, as TestOne.foo() and TestTwo.foo() failed, I saw two MySuite.foo errors in my JUnit report. Of course I can retrieve the name of the test class by reading the logs of the failed test, but it's not really a solution...

So my question is to know if I can force Surefire (or JUnit?) to indicate the name of test class.

Thanks.


回答1:


I get a single file per test class, so it took me a moment to figure this one out: You're using a test suite.

When using test suites, all the test results end up in a single file with the name of the suite.

There is no option to change this behavior. Try to file a feature request.



来源:https://stackoverflow.com/questions/6033742/is-there-a-way-to-force-maven-surefire-or-junit-to-indicate-the-name-of-the-fail

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!