8000 add more junit 5 tests · fishercoder1534/RandomJava@61a75ba · GitHub
[go: up one dir, main page]

Skip to content
Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 61a75ba

Browse files
add more junit 5 tests
1 parent 16f3b25 commit 61a75ba

File tree

2 files changed

+84
-2
lines changed

2 files changed

+84
-2
lines changed

pom.xml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,13 @@
5050
<dependency>
5151
<groupId>org.junit.jupiter</groupId>
5252
<artifactId>junit-jupiter-engine</artifactId>
53-
<version>5.9.1</version>
54-
<scope>test</scope>
53+
<version>5.9.2</version>
54+
</dependency>
55+
56+
<dependency>
57+
<groupId>org.junit.jupiter</groupId>
58+
<artifactId>junit-jupiter-params</artifactId>
59+
<version>5.9.0</version>
5560
</dependency>
5661

5762
<!-- spring-context which provides core functionality -->

src/test/junit5/Junit5Test.java

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package junit5;
2+
3+
import org.apache.logging.log4j.util.Strings;
4+
import org.junit.jupiter.api.AfterAll;
5+
import org.junit.jupiter.api.AfterEach;
6+
import org.junit.jupiter.api.BeforeAll;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.DisplayName;
9+
import org.junit.jupiter.api.Test;
10+
import org.junit.jupiter.params.ParameterizedTest;
11+
import org.junit.jupiter.params.provider.Arg 8000 uments;
12+
import org.junit.jupiter.params.provider.MethodSource;
13+
14+
import java.util.stream.Stream;
15+
16+
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertThrows;
18+
19+
public class Junit5Test {
20+
@BeforeAll
21+
static void setup() {
22+
System.out.println("@BeforeAll - executes once before all test methods in this class");
23+
}
24+
25+
@BeforeEach
26+
void init() {
27+
System.out.println("@BeforeEach - executes before each test method in this class");
28+
}
29+
30+
@DisplayName("Single test successful")
31+
@Test
32+
void testSingleSuccessTest() {
33+
System.out.println("Success");
34+
assertEquals(5 + 2, 7);
35+
}
36+
37+
@Test
38+
void shouldThrowException() {
39+
Throwable exception = assertThrows(UnsupportedOperationException.class, () -> {
40+
throw new UnsupportedOperationException("Not supported");
41+
});
42+
assertEquals("Not supported", exception.getMessage());
43+
}
44+
45+
@Test
46+
void assertThrowsException() {
47+
String str = null;
48+
assertThrows(IllegalArgumentException.class, () -> {
49+
Integer.valueOf(str);
50+
});
51+
}
52+
53+
@ParameterizedTest
54+
@MethodSource("data")
55+
public void parameterizedTest(String input, boolean expected) {
56+
assertEquals(expected, Strings.isBlank(input));
57+
}
58+
59+
private static Stream<Arguments> data() {
60+
return Stream.of(
61+
Arguments.of(null, true),
62+
Arguments.of("", true),
63+
Arguments.of(" ", true),
64+
Arguments.of("not blank", false)
65+
);
66+
}
67+
68+
@AfterEach
69+
void tearDown() {
70+
System.out.println("@AfterEach - executed after each test method.");
71+
}
72+
73+
@AfterAll
74+
static void done() {
75+
System.out.println("@AfterAll - executed after all test methods.");
76+
}
77+
}

0 commit comments

Comments
 (0)
0