You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importjava.lang.reflect.Method;
importorg.junit.jupiter.api.DisplayName;
importorg.junit.jupiter.api.DisplayNameGeneration;
importorg.junit.jupiter.api.DisplayNameGenerator;
importorg.junit.jupiter.api.Nested;
importorg.junit.jupiter.api.Test;
importorg.junit.jupiter.params.ParameterizedTest;
importorg.junit.jupiter.params.provider.ValueSource;
classDisplayNameGeneratorDemo {
@Nested@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
classA_year_is_not_supported {
@Testvoidif_it_is_zero() {
}
@DisplayName("A negative value for year is not supported by the leap year computation.")
@ParameterizedTest(name = "For example, year {0} is not supported.")
@ValueSource(ints = { -1, -4 })
voidif_it_is_negative(intyear) {
}
}
@Nested@DisplayNameGeneration(IndicativeSentences.class)
classA_year_is_a_leap_year {
@Testvoidif_it_is_divisible_by_4_but_not_by_100() {
}
@ParameterizedTest(name = "Year {0} is a leap year.")
@ValueSource(ints = { 2016, 2020, 2048 })
voidif_it_is_one_of_the_following_years(intyear) {
}
}
staticclassIndicativeSentencesextendsDisplayNameGenerator.ReplaceUnderscores {
@OverridepublicStringgenerateDisplayNameForClass(Class<?> testClass) {
returnsuper.generateDisplayNameForClass(testClass);
}
@OverridepublicStringgenerateDisplayNameForNestedClass(Class<?> nestedClass) {
returnsuper.generateDisplayNameForNestedClass(nestedClass) + "...";
}
@OverridepublicStringgenerateDisplayNameForMethod(Class<?> testClass, MethodtestMethod) {
Stringname = testClass.getSimpleName() + ' ' + testMethod.getName();
returnname.replace('_', ' ') + '.';
}
}
}
Should yield
+-- DisplayNameGeneratorDemo [OK]
+-- A year is not supported [OK]
| +-- A negative value for year is not supported by the leap year computation. [OK]
| | +-- For example, year -1 is not supported. [OK]
| | '-- For example, year -4 is not supported. [OK]
| '-- if it is zero() [OK]
'-- A year is a leap year... [OK]
+-- A year is a leap year if it is divisible by 4 but not by 100. [OK]
'-- A year is a leap year if it is one of the following years. [OK]
+-- Year 2016 is a leap year. [OK]
+-- Year 2020 is a leap year. [OK]
'-- Year 2048 is a leap year. [OK]
The text was updated successfully, but these errors were encountered:
Following up on #446,
@DisplayNameGeneration
generators from Junit 5.4 should be supported. See https://junit.org/junit5/docs/5.4.0/user-guide/index.html#writing-tests-display-name-generatorShould yield
The text was updated successfully, but these errors were encountered: