Skip to content

Commit 7e32167

Browse files
feat(display name generation): added examples
1 parent 0af10c7 commit 7e32167

3 files changed

Lines changed: 54 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ JUnit 6 examples
99
* @ParameterizedTest
1010
* @RepeatedTest
1111
* @TestFactory
12+
* @DisplayNameGeneration
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package de.claudioaltamura.java.junit6;
2+
3+
import org.junit.jupiter.api.DisplayNameGeneration;
4+
import org.junit.jupiter.api.DisplayNameGenerator;
5+
import org.junit.jupiter.api.Test;
6+
import org.junit.jupiter.params.ParameterizedTest;
7+
import org.junit.jupiter.params.provider.ValueSource;
8+
9+
import static org.junit.jupiter.api.Assertions.assertTrue;
10+
11+
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
12+
class DisplayNameIndicativeSentencesGenerationExampleTest {
13+
14+
15+
@Test
16+
void if_it_is_divisible_by_4_but_not_by_100() {
17+
assertTrue(true, "This test should pass for years divisible by 4 but not by 100");
18+
}
19+
20+
@ParameterizedTest(name = "Year {0} is a leap year.")
21+
@ValueSource(ints = { 2016, 2020, 2048 })
22+
void if_it_is_one_of_the_following_years(int year) {
23+
assertTrue(year % 4 == 0 && year % 100 != 0, "This test should pass for leap years");
24+
}
25+
26+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package de.claudioaltamura.java.junit6;
2+
3+
import org.junit.jupiter.api.DisplayName;
4+
import org.junit.jupiter.api.DisplayNameGeneration;
5+
import org.junit.jupiter.api.DisplayNameGenerator;
6+
import org.junit.jupiter.api.Test;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.ValueSource;
9+
10+
import static org.junit.jupiter.api.Assertions.assertTrue;
11+
12+
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class)
13+
class DisplayNameReplaceUnderscoresExampleTest {
14+
15+
@Test
16+
void if_it_is_zero() {
17+
assertTrue(true, "This test should pass for year 0");
18+
}
19+
20+
@DisplayName("A negative value for year is not supported by the leap year computation.")
21+
@ParameterizedTest(name = "For example, year {0} is not supported.")
22+
@ValueSource(ints = { -1, -4 })
23+
void if_it_is_negative(int year) {
24+
assertTrue(year < 0, "This test should pass for negative years");
25+
}
26+
27+
}

0 commit comments

Comments
 (0)