My question is: is there a way to force Maven Surefire (or JUnit?) To specify the name of the failed test class when this class was executed from the test package?
Now, a long story.
Imagine you have a JUnit test suite that runs 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 test suite:
@RunWith(Suite.class)
@SuiteClasses(value = { TestOne.class, TestTwo.class })
public class MySuite {
}
Now, if I run the test package ( mvn test -Dtest=MySuite), I will get 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
Therefore, reading these lines, I can easily find out which classes and tests fail.
target/surefire-reports/ , MySuite.txt, .
, :
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
, , , , TestOne.foo() TestTwo.foo() MySuite.foo JUnit.
, , , ...
, - , Surefire ( JUnit?) .
.