Is there anyway we can achieve dynamic DisplayName in Junit 5 ( eg : replace with system properties )
@DisplayName("The test cases is running agains {os.name}")
public void testOSVersion(){
.....
}
We want to do this to make test cases more descriptive.
Thanks
It is not possible by default.
TestReporter
With the current Jupiter versions you may always use the TestReporter
to emit extra data to the reports:
@Test
void testOSVersion(TestReporter testReporter) {
testReporter.publishEntry("os.name", System.getProperty("os.name"));
}
For details see https://junit.org/junit5/docs/current/user-guide/#writing-tests-dependency-injection
DisplayNameGenerator
The upcoming version 5.4.0 of Jupiter, available as a SNAPSHOT already, supports an annotation called @DisplayNameGeneration
that points to a custom DisplayNameGenerator
implementation. Here you may generate a display name for a test method dynamically, using it's name, attached annotations, etc...
For details, see https://junit.org/junit5/docs/snapshot/user-guide/#display-name-generators
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.