junit5
junit5 copied to clipboard
DisplayNameGenerator should be able to fall back to default
Motivation :
Having the configuration can be useful to fallback on the default DisplayNameGenerator
Example :
@DisplayNameGeneration(MyTest.MyDisplayNameGenerator.class)
public class MyTest {
@Test
@MyDisplayName("My display name")
public void test1() {
// a test
}
@Test
public void test2() {
// a test
}
static class MyDisplayNameGenerator implements DisplayNameGenerator {
@Override
public String generateDisplayNameForClass(Class<?> testClass, JupiterConfiguration configuration) {
return configuration.getDefaultDisplayNameGenerator().generateDisplayNameForClass(testClass, configuration);
}
@Override
public String generateDisplayNameForNestedClass(Class<?> nestedClass, JupiterConfiguration configuration) {
return configuration.getDefaultDisplayNameGenerator().generateDisplayNameForNestedClass(nestedClass, configuration);
}
@Override
public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod, JupiterConfiguration configuration) {
Optional<MyDisplayName> optional = findAnnotation(testMethod, MyDisplayName.class);
return optional.map(MyDisplayName::value)
.orElseGet(() -> configuration.getDefaultDisplayNameGenerator().generateDisplayNameForMethod(testClass, testMethod, configuration));
}
}
}
JupiterConfiguration
is an internal class in junit-jupiter-engine so it cannot be passed as-is to DisplayNameGenerator
which is in junit-jupiter-api. But I can see that falling back to the default would be useful. I think the smallest API change would be to allow DisplayNameGenerators
to return null
which would then be checked in the engine code.
@d-william Would that work for you?
JupiterConfiguration
is an internal class in junit-jupiter-engine so it cannot be passed as-is toDisplayNameGenerator
which is in junit-jupiter-api. But I can see that falling back to the default would be useful. I think the smallest API change would be to allowDisplayNameGenerators
to returnnull
which would then be checked in the engine code.@d-william Would that work for you?
Yes 🙂
Team Decision: Allow methods in DisplayNameGenerator
to return null
to signal to fall back to the default generator.
@d-william Would you be interested in submitting a PR for this?
I could spend some time on this if there are no objections.
@gilbertojrequena Go for it! 👍
@d-william Would you be interested in submitting a PR for this?
Sorry for the late reply, I think I can handle it if it is still possible
@d-william Would you be interested in submitting a PR for this?
Sorry for the late reply, I think I can handle it if it is still possible
No worries, go ahead :) @marcphilipp could you assign this to @d-william ?