Skip to content

Commit 2cc8012

Browse files
committed
some update
1 parent 8b331b5 commit 2cc8012

File tree

265 files changed

+5467
-534
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

265 files changed

+5467
-534
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ mvn test surefire-report:report
1717
## maven 构建完整命令
1818
mvn clean install checkstyle:checkstyle surefire-report:report site
1919

20-
注:本项目以 [白盒测试实验](https://gitee.com/huizhuoli/white_box_test_experiment) 为起点,并在此为基础上逐步完善出一套完整的开放测试套件,包含更多的测试用例和应用场景,支持 TDD 和 BDD 等编程范式。
21-
2220
## TDD & BDD
2321
![tdd-bdd](https://wiki.huihoo.com/images/9/97/Tdd-and-bdd.png)
2422

@@ -29,4 +27,6 @@ mvn clean install checkstyle:checkstyle surefire-report:report site
2927
Build the thing right 和 Build the right thing.
3028

3129
## 参与
32-
欢迎大家提交更多测试用例和应用场景,将 TDD & BDD 更好融入整个研发流程。
30+
欢迎大家提交更多测试用例和应用场景,将 TDD & BDD 更好融入整个研发流程。
31+
32+
注:本项目以 [白盒测试实验](https://gitee.com/huizhuoli/white_box_test_experiment) 为起点,并在此为基础上逐步完善出一套完整的开放测试套件,包含更多的测试用例和应用场景,支持 TDD 和 BDD 等编程范式。

pom.xml

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,25 @@
3333
</properties>
3434

3535
<dependencies>
36-
<dependency>
37-
<groupId>org.junit.jupiter</groupId>
38-
<artifactId>junit-jupiter-engine</artifactId>
39-
<version>${junit.jupiter.version}</version>
40-
</dependency>
36+
37+
<dependency>
38+
<groupId>org.junit.platform</groupId>
39+
<artifactId>junit-platform-launcher</artifactId>
40+
<version>1.7.2</version>
41+
<scope>test</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.junit.jupiter</groupId>
45+
<artifactId>junit-jupiter-engine</artifactId>
46+
<version>5.7.2</version>
47+
<scope>test</scope>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.junit.vintage</groupId>
51+
<artifactId>junit-vintage-engine</artifactId>
52+
<version>5.7.2</version>
53+
<scope>test</scope>
54+
</dependency>
4155

4256
<dependency>
4357
<groupId>org.junit.jupiter</groupId>
@@ -121,8 +135,8 @@
121135
<!-- maven 编译结束 -->
122136
<plugin>
123137
<artifactId>maven-surefire-plugin</artifactId>
124-
<!-- JUnit 5 requires Surefire version 2.22.0 or higher -->
125-
<version>${maven.surefire.plugin.version}</version>
138+
<!-- JUnit 5 requires Surefire version 2.22.0 or higher, Two plugin versions (2.22.1 and 3.0.0-M1) -->
139+
<version>3.0.0-M1</version>
126140
<configuration>
127141
<testFailureIgnore>true</testFailureIgnore>
128142
<includes>

src/test/java/open/testing/suite/junit5/MyAnnotations.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import org.junit.jupiter.api.Tag;
99
import org.junit.jupiter.api.Test;
1010

11+
/*
12+
* https://junit.org/junit5/docs/current/user-guide/#writing-tests-annotations
13+
*/
1114
public class MyAnnotations {
1215

1316
@Target(ElementType.METHOD)

src/test/java/open/testing/suite/junit5/MyAssertions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
import org.junit.jupiter.api.Test;
1919

20+
/*
21+
* https://junit.org/junit5/docs/current/user-guide/#writing-tests-assertions
22+
*/
23+
2024
public class MyAssertions {
2125
}
2226

src/test/java/open/testing/suite/junit5/MyDisplayName.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
import org.junit.jupiter.api.DisplayName;
44
import org.junit.jupiter.api.Test;
55

6+
/*
7+
* https://junit.org/junit5/docs/current/user-guide/#writing-tests-display-names
8+
*/
9+
610
public class MyDisplayName {
711
}
812

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package open.testing.suite.junit5;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertNotNull;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
import static org.junit.jupiter.api.DynamicContainer.dynamicContainer;
8+
import static org.junit.jupiter.api.DynamicTest.dynamicTest;
9+
10+
import java.util.Arrays;
11+
import java.util.Collection;
12+
import java.util.Iterator;
13+
import java.util.List;
14+
import java.util.Random;
15+
import java.util.function.Function;
16+
import java.util.stream.IntStream;
17+
import java.util.stream.Stream;
18+
19+
import open.testing.suite.unittest.demo.Calculator;
20+
21+
import org.junit.jupiter.api.DynamicNode;
22+
import org.junit.jupiter.api.DynamicTest;
23+
import org.junit.jupiter.api.Tag;
24+
import org.junit.jupiter.api.TestFactory;
25+
import org.junit.jupiter.api.function.ThrowingConsumer;
26+
27+
/*
28+
* https://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests
29+
*/
30+
31+
public class MyDynamicTests {
32+
}
33+
34+
class DynamicTestsDemo {
35+
36+
private final Calculator calculator = new Calculator();
37+
38+
// This will result in a JUnitException!
39+
@TestFactory
40+
List<String> dynamicTestsWithInvalidReturnType() {
41+
return Arrays.asList("Hello");
42+
}
43+
44+
@TestFactory
45+
Stream<DynamicTest> dynamicTestsFromIntStream() {
46+
// Generates tests for the first 10 even integers.
47+
return IntStream.iterate(0, n -> n + 2).limit(10)
48+
.mapToObj(n -> dynamicTest("test" + n, () -> assertTrue(n % 2 == 0)));
49+
}
50+
51+
@TestFactory
52+
Stream<DynamicTest> generateRandomNumberOfTestsFromIterator() {
53+
54+
// Generates random positive integers between 0 and 100 until
55+
// a number evenly divisible by 7 is encountered.
56+
Iterator<Integer> inputGenerator = new Iterator<Integer>() {
57+
58+
Random random = new Random();
59+
int current;
60+
61+
@Override
62+
public boolean hasNext() {
63+
current = random.nextInt(100);
64+
return current % 7 != 0;
65+
}
66+
67+
@Override
68+
public Integer next() {
69+
return current;
70+
}
71+
};
72+
73+
// Generates display names like: input:5, input:37, input:85, etc.
74+
Function<Integer, String> displayNameGenerator = (input) -> "input:" + input;
75+
76+
// Executes tests based on the current input value.
77+
ThrowingConsumer<Integer> testExecutor = (input) -> assertTrue(input % 7 != 0);
78+
79+
// Returns a stream of dynamic tests.
80+
return DynamicTest.stream(inputGenerator, displayNameGenerator, testExecutor);
81+
}
82+
83+
84+
@TestFactory
85+
Stream<DynamicNode> dynamicTestsWithContainers() {
86+
return Stream.of("A", "B", "C")
87+
.map(input -> dynamicContainer("Container " + input, Stream.of(
88+
dynamicTest("not null", () -> assertNotNull(input)),
89+
dynamicContainer("properties", Stream.of(
90+
dynamicTest("length > 0", () -> assertTrue(input.length() > 0)),
91+
dynamicTest("not empty", () -> assertFalse(input.isEmpty()))
92+
))
93+
)));
94+
}
95+
96+
97+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package open.testing.suite.junit5;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertFalse;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
6+
import static org.junit.jupiter.api.Assertions.assertTrue;
7+
8+
import java.util.EmptyStackException;
9+
import java.util.Stack;
10+
11+
import org.junit.jupiter.api.BeforeEach;
12+
import org.junit.jupiter.api.DisplayName;
13+
import org.junit.jupiter.api.Nested;
14+
import org.junit.jupiter.api.Test;
15+
16+
/*
17+
* https://junit.org/junit5/docs/current/user-guide/#writing-tests-nested
18+
*/
19+
20+
public class MyNestedTests {
21+
}
22+
23+
@DisplayName("A stack")
24+
class TestingAStackDemo {
25+
26+
Stack<Object> stack;
27+
28+
@Test
29+
@DisplayName("is instantiated with new Stack()")
30+
void isInstantiatedWithNew() {
31+
new Stack<>();
32+
}
33+
34+
@Nested
35+
@DisplayName("when new")
36+
class WhenNew {
37+
38+
@BeforeEach
39+
void createNewStack() {
40+
stack = new Stack<>();
41+
}
42+
43+
@Test
44+
@DisplayName("is empty")
45+
void isEmpty() {
46+
assertTrue(stack.isEmpty());
47+
}
48+
49+
@Test
50+
@DisplayName("throws EmptyStackException when popped")
51+
void throwsExceptionWhenPopped() {
52+
assertThrows(EmptyStackException.class, stack::pop);
53+
}
54+
55+
@Test
56+
@DisplayName("throws EmptyStackException when peeked")
57+
void throwsExceptionWhenPeeked() {
58+
assertThrows(EmptyStackException.class, stack::peek);
59+
}
60+
61+
@Nested
62+
@DisplayName("after pushing an element")
63+
class AfterPushing {
64+
65+
String anElement = "an element";
66+
67+
@BeforeEach
68+
void pushAnElement() {
69+
stack.push(anElement);
70+
}
71+
72+
@Test
73+
@DisplayName("it is no longer empty")
74+
void isNotEmpty() {
75+
assertFalse(stack.isEmpty());
76+
}
77+
78+
@Test
79+
@DisplayName("returns the element when popped and is empty")
80+
void returnElementWhenPopped() {
81+
assertEquals(anElement, stack.pop());
82+
assertTrue(stack.isEmpty());
83+
}
84+
85+
@Test
86+
@DisplayName("returns the element when peeked but remains not empty")
87+
void returnElementWhenPeeked() {
88+
assertEquals(anElement, stack.peek());
89+
assertFalse(stack.isEmpty());
90+
}
91+
}
92+
}
93+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package open.testing.suite.junit5;
2+
3+
import org.junit.jupiter.api.DisplayName;
4+
import org.junit.jupiter.params.provider.CsvSource;
5+
import org.junit.jupiter.params.provider.EnumSource;
6+
import org.junit.jupiter.params.provider.ValueSource;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
9+
import static org.junit.Assert.assertNotEquals;
10+
import static org.junit.Assert.assertNotNull;
11+
import static org.junit.jupiter.api.Assertions.assertTrue;
12+
import org.junit.platform.commons.util.StringUtils;
13+
14+
import java.time.temporal.ChronoUnit;
15+
import java.time.temporal.TemporalUnit;
16+
17+
/*
18+
* https://junit.org/junit5/docs/current/user-guide/#writing-tests-parameterized-tests
19+
*/
20+
21+
public class MyParameterizedTests {
22+
23+
@ParameterizedTest
24+
@ValueSource(strings = { "racecar", "radar", "able was I ere I saw elba" })
25+
void palindromes(String candidate) {
26+
assertTrue(StringUtils.containsWhitespace(candidate));
27+
//assertTrue(StringUtils.isPalindrome(candidate));
28+
}
29+
30+
@ParameterizedTest
31+
@ValueSource(ints = { 1, 2, 3, 4, 5, 6, 7 })
32+
void testWithValueSource(int argument) {
33+
assertTrue(argument > 0 && argument < 10);
34+
}
35+
36+
@ParameterizedTest
37+
@EnumSource(ChronoUnit.class)
38+
void testWithEnumSource(TemporalUnit unit) {
39+
assertNotNull(unit);
40+
}
41+
42+
@DisplayName("Display name of container")
43+
@ParameterizedTest(name = "{index} ==> the rank of ''{0}'' is {1}")
44+
@CsvSource({ "apple, 1", "banana, 2", "'lemon, lime', 3" })
45+
void testWithCustomDisplayNames(String fruit, int rank) {
46+
}
47+
48+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
JUnit 5 resource
2+
https://junit.org/junit5/docs/current/user-guide/
3+
https://github.com/junit-team/junit5/wiki/Third-party-Extensions

target/checkstyle-cachefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#Wed Jul 14 11:55:56 CST 2021
1+
#Wed Jul 14 15:36:59 CST 2021
22
configuration*?=4E24F3B940C316EC64E715B7D80323EC27A76A84

0 commit comments

Comments
 (0)