Skip to content

Commit d67d03b

Browse files
yasin3061maibin
authored andcommitted
BAEL-899 Guide to @RepeatedTest in Junit 5 (eugenp#1815)
* BAEL-88 Testing in Spring Boot * BAEL-88 Integration tests fixed. * BAEL-905 Improvement task for spring boot testing * BAEL-905 Improvement task for spring boot testing * BAEL-926 Upgrade Junit 5 dependencies to use M4 * BAEL-899 Guide to @RepeatedTest in Junit 5
1 parent 9692ae3 commit d67d03b

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.baeldung;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.AfterEach;
6+
import org.junit.jupiter.api.BeforeEach;
7+
import org.junit.jupiter.api.RepeatedTest;
8+
import org.junit.jupiter.api.RepetitionInfo;
9+
import org.junit.jupiter.api.TestInfo;
10+
11+
public class RepeatedTestExample {
12+
13+
@BeforeEach
14+
void beforeEachTest() {
15+
System.out.println("Before Each Test");
16+
}
17+
18+
@AfterEach
19+
void afterEachTest() {
20+
System.out.println("After Each Test");
21+
System.out.println("=====================");
22+
}
23+
24+
@RepeatedTest(3)
25+
void repeatedTest(TestInfo testInfo) {
26+
System.out.println("Executing repeated test");
27+
assertEquals(2, Math.addExact(1, 1), "1 + 1 should equal 2");
28+
}
29+
30+
@RepeatedTest(value = 3, name = RepeatedTest.LONG_DISPLAY_NAME)
31+
void repeatedTestWithLongName() {
32+
System.out.println("Executing repeated test with long name");
33+
assertEquals(2, Math.addExact(1, 1), "1 + 1 should equal 2");
34+
}
35+
36+
@RepeatedTest(value = 3, name = RepeatedTest.SHORT_DISPLAY_NAME)
37+
void repeatedTestWithShortName() {
38+
System.out.println("Executing repeated test with long name");
39+
assertEquals(2, Math.addExact(1, 1), "1 + 1 should equal 2");
40+
}
41+
42+
@RepeatedTest(value = 3, name = "Custom name {currentRepetition}/{totalRepetitions}")
43+
void repeatedTestWithCustomDisplayName() {
44+
assertEquals(2, Math.addExact(1, 1), "1 + 1 should equal 2");
45+
}
46+
47+
@RepeatedTest(3)
48+
void repeatedTestWithRepetitionInfo(RepetitionInfo repetitionInfo) {
49+
System.out.println("Repetition #" + repetitionInfo.getCurrentRepetition());
50+
assertEquals(3, repetitionInfo.getTotalRepetitions());
51+
}
52+
}

0 commit comments

Comments
 (0)