'Maven surefire plugin + JUnit5 dynamic tests - how to override test naming?
Assume we have a JUnit5 dynamic test like this:
public class ProbaTest {
@TestFactory
public Iterable<DynamicNode> tests() {
return Collections.singleton(
DynamicTest.dynamicTest("aaa", () -> {
throw new AssertionError("FAIL, as planned");
})
);
}
}
When being ran by Surefire Maven plugin, it fails in the following way:
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ proba-retrolambda ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.proba.ProbaTest
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.025 s <<< FAILURE! - in com.proba.ProbaTest
[ERROR] tests[1] Time elapsed: 0.007 s <<< FAILURE!
java.lang.AssertionError: FAIL, as planned
at com.proba.ProbaTest.lambda$tests$0(ProbaTest.java:14)
[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR] ProbaTest.lambda$tests$0:14 FAIL, as planned
[INFO]
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0
Notable thing about the output is the dynamic name, given to the test by JUnit5 - "tests[1]". It doesn't use the "aaa" display name, given by the test factory, and as far as I saw, there are reasons for that.
I wonder, however - is there a way of explicitly overriding the naming behavior? Is there any way of how can I provide explicit names for a dynamic JUnit test cases by my own?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|