Skip to content

Commit 62da08b

Browse files
Feat/optimize test (#116)
* feat: optimize test
1 parent 8e36003 commit 62da08b

21 files changed

Lines changed: 324 additions & 276 deletions

pom.xml

Lines changed: 63 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -82,22 +82,28 @@
8282
</modules>
8383
<properties>
8484
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
85-
<maven.test.skip>false</maven.test.skip>
86-
<maven.deploy.skip>false</maven.deploy.skip>
87-
<maven.deploy.version>3.0.0</maven.deploy.version>
88-
<maven.shade.version>3.5.0</maven.shade.version>
89-
<maven.source.version>3.0.1</maven.source.version>
90-
<maven.exec.version>3.0.1</maven.exec.version>
91-
<maven.jar.version>3.1.2</maven.jar.version>
9285
<maven.compiler.source>17</maven.compiler.source>
9386
<maven.compiler.target>17</maven.compiler.target>
94-
<maven.compiler.version>3.7.0</maven.compiler.version>
95-
<maven.gpg.version>3.1.0</maven.gpg.version>
87+
<maven.compiler.release>17</maven.compiler.release>
88+
89+
<maven.test.skip>false</maven.test.skip>
9690
<maven.ignore.testfailure>false</maven.ignore.testfailure>
97-
<maven.surefire.version>3.1.2</maven.surefire.version>
98-
<maven.javadoc.version>3.0.1</maven.javadoc.version>
91+
<maven.deploy.skip>false</maven.deploy.skip>
92+
<maven.compiler.version>3.11.0</maven.compiler.version>
93+
<maven.surefire.version>3.0.0-M9</maven.surefire.version>
94+
<maven.failsafe.version>3.0.0-M9</maven.failsafe.version>
95+
<maven.jar.version>3.3.0</maven.jar.version>
96+
<maven.source.version>3.3.0</maven.source.version>
97+
<maven.javadoc.version>3.5.0</maven.javadoc.version>
98+
<maven.deploy.version>3.1.1</maven.deploy.version>
99+
<maven.shade.version>3.4.1</maven.shade.version>
100+
<maven.exec.version>3.1.0</maven.exec.version>
101+
<maven.gpg.version>3.1.0</maven.gpg.version>
102+
103+
<jacoco.version>0.8.11</jacoco.version>
99104
<central-publishing-maven-plugin.version>0.7.0</central-publishing-maven-plugin.version>
100105
<exec.maven.version>3.1.0</exec.maven.version>
106+
<junit.version>5.14.2</junit.version>
101107
<file.encoding>UTF-8</file.encoding>
102108
</properties>
103109

@@ -124,46 +130,19 @@
124130
<dependency>
125131
<groupId>org.junit.jupiter</groupId>
126132
<artifactId>junit-jupiter-api</artifactId>
127-
<version>5.9.3</version>
133+
<version>${junit.version}</version>
128134
<scope>test</scope>
129135
</dependency>
130136
<dependency>
131137
<groupId>org.junit.jupiter</groupId>
132138
<artifactId>junit-jupiter-engine</artifactId>
133-
<version>5.9.3</version>
134-
<scope>test</scope>
135-
</dependency>
136-
<!-- 保留 JUnit 4 测试 -->
137-
<dependency>
138-
<groupId>junit</groupId>
139-
<artifactId>junit</artifactId>
140-
<version>4.13.2</version>
139+
<version>${junit.version}</version>
141140
<scope>test</scope>
142141
</dependency>
143-
<!-- <dependency>-->
144-
<!-- <groupId>org.powermock</groupId>-->
145-
<!-- <artifactId>powermock-module-junit4</artifactId>-->
146-
<!-- <scope>test</scope>-->
147-
<!-- </dependency>-->
148-
<!-- <dependency>-->
149-
<!-- <groupId>org.powermock</groupId>-->
150-
<!-- <artifactId>powermock-api-mockito2</artifactId>-->
151-
<!-- <scope>test</scope>-->
152-
<!-- </dependency>-->
153-
<!-- <dependency>-->
154-
<!-- <groupId>org.powermock</groupId>-->
155-
<!-- <artifactId>powermock-api-support</artifactId>-->
156-
<!-- <scope>test</scope>-->
157-
<!-- </dependency>-->
158-
<!-- <dependency>-->
159-
<!-- <groupId>org.powermock</groupId>-->
160-
<!-- <artifactId>powermock-module-junit4-rule</artifactId>-->
161-
<!-- <scope>test</scope>-->
162-
<!-- </dependency>-->
163142
<dependency>
164143
<groupId>org.jacoco</groupId>
165144
<artifactId>org.jacoco.agent</artifactId>
166-
<version>0.8.11</version>
145+
<version>${jacoco.version}</version>
167146
<classifier>runtime</classifier>
168147
<scope>test</scope>
169148
</dependency>
@@ -199,14 +178,14 @@
199178
<argLine>
200179
--add-opens java.base/java.lang=ALL-UNNAMED
201180
--add-opens java.base/java.util=ALL-UNNAMED
181+
--add-opens java.base/java.io=ALL-UNNAMED
202182
</argLine>
203183
<testFailureIgnore>${maven.ignore.testfailure}</testFailureIgnore>
204184
<skipTests>false</skipTests>
205-
<systemPropertyVariables>
206-
<jacoco-agent.destfile>${project.build.directory}/coverage.exec
207-
</jacoco-agent.destfile>
208-
</systemPropertyVariables>
209185
<reportsDirectory>../../site/junit</reportsDirectory>
186+
<useSystemClassLoader>false</useSystemClassLoader>
187+
<forkCount>1</forkCount>
188+
<reuseForks>true</reuseForks>
210189
</configuration>
211190
</plugin>
212191
<plugin>
@@ -272,22 +251,22 @@
272251
<plugin>
273252
<groupId>org.jacoco</groupId>
274253
<artifactId>jacoco-maven-plugin</artifactId>
275-
<version>0.8.8</version>
254+
<version>${jacoco.version}</version>
276255
<configuration>
277256
<skip>false</skip>
257+
<destFile>${project.build.directory}/coverage.exec</destFile>
258+
<append>true</append>
278259
</configuration>
279260
<executions>
280261
<execution>
281-
<id>default-instrument</id>
282-
<goals>
283-
<goal>instrument</goal>
284-
</goals>
285-
</execution>
286-
<execution>
287-
<id>default-restore-instrumented-classes</id>
262+
<id>prepare-agent</id>
288263
<goals>
289-
<goal>restore-instrumented-classes</goal>
264+
<goal>prepare-agent</goal>
290265
</goals>
266+
<configuration>
267+
<propertyName>surefireArgLine</propertyName>
268+
<destFile>${project.build.directory}/coverage.exec</destFile>
269+
</configuration>
291270
</execution>
292271
<execution>
293272
<id>report</id>
@@ -300,13 +279,39 @@
300279
<outputDirectory>../../site/${project.artifactId}</outputDirectory>
301280
</configuration>
302281
</execution>
282+
<execution>
283+
<id>aggregate</id>
284+
<phase>verify</phase>
285+
<goals>
286+
<goal>report-aggregate</goal>
287+
</goals>
288+
</execution>
303289
</executions>
304290
</plugin>
305291
<plugin>
306292
<groupId>org.codehaus.mojo</groupId>
307293
<artifactId>exec-maven-plugin</artifactId>
308294
<version>${exec.maven.version}</version>
309295
</plugin>
296+
<plugin>
297+
<groupId>org.apache.maven.plugins</groupId>
298+
<artifactId>maven-failsafe-plugin</artifactId>
299+
<version>${maven.failsafe.version}</version>
300+
<configuration>
301+
<argLine>
302+
--add-opens java.base/java.lang=ALL-UNNAMED
303+
--add-opens java.base/java.util=ALL-UNNAMED
304+
</argLine>
305+
</configuration>
306+
<executions>
307+
<execution>
308+
<goals>
309+
<goal>integration-test</goal>
310+
<goal>verify</goal>
311+
</goals>
312+
</execution>
313+
</executions>
314+
</plugin>
310315
</plugins>
311316
</pluginManagement>
312317

@@ -327,6 +332,10 @@
327332
<groupId>org.jacoco</groupId>
328333
<artifactId>jacoco-maven-plugin</artifactId>
329334
</plugin>
335+
<plugin>
336+
<groupId>org.apache.maven.plugins</groupId>
337+
<artifactId>maven-failsafe-plugin</artifactId>
338+
</plugin>
330339
</plugins>
331340
</build>
332341

trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/YamlUtilsTest.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
import java.util.HashMap;
1717
import java.util.List;
1818
import java.util.Map;
19-
import org.junit.After;
20-
import org.junit.Assert;
21-
import org.junit.Before;
22-
import org.junit.Test;
19+
import org.junit.jupiter.api.AfterEach;
20+
import org.junit.jupiter.api.Assertions;
21+
import org.junit.jupiter.api.BeforeEach;
22+
import org.junit.jupiter.api.Test;
2323

2424

2525
/**
@@ -31,7 +31,7 @@ public class YamlUtilsTest {
3131

3232
private YamlUtils yamlUtils;
3333

34-
@Before
34+
@BeforeEach
3535
public void setUp() throws Exception {
3636
this.properties = new HashMap<>();
3737
properties.put("string", "string");
@@ -41,72 +41,72 @@ public void setUp() throws Exception {
4141
this.yamlUtils = new YamlUtils("");
4242
}
4343

44-
@After
44+
@AfterEach
4545
public void tearDown() throws Exception {
4646
properties.clear();
4747
}
4848

4949
@Test
5050
public void testGetString() {
5151
String string = yamlUtils.getString(properties, "string");
52-
Assert.assertEquals("string", string);
52+
Assertions.assertEquals("string", string);
5353

5454
properties.put("string", null);
5555

5656
try {
5757
yamlUtils.getString(properties, "string");
5858
} catch (Exception e) {
59-
Assert.assertTrue(e instanceof IllegalArgumentException);
59+
Assertions.assertTrue(e instanceof IllegalArgumentException);
6060
}
6161
}
6262

6363
@Test
6464
public void testGetInteger() {
6565
int integer = yamlUtils.getInteger(properties, "integer");
66-
Assert.assertEquals(integer, 10);
66+
Assertions.assertEquals(integer, 10);
6767

6868
properties.put("integer", null);
6969

7070
try {
7171
yamlUtils.getInteger(properties, "integer");
7272
} catch (Exception e) {
73-
Assert.assertTrue(e instanceof IllegalArgumentException);
73+
Assertions.assertTrue(e instanceof IllegalArgumentException);
7474
}
7575
}
7676

7777
@Test
7878
public void testGetBoolean() {
7979
boolean bool = yamlUtils.getBoolean(properties, "boolean");
80-
Assert.assertTrue(bool);
80+
Assertions.assertTrue(bool);
8181

8282
properties.put("boolean", null);
8383
try {
8484
yamlUtils.getBoolean(properties, "boolean");
8585
} catch (Exception e) {
86-
Assert.assertTrue(e instanceof IllegalArgumentException);
86+
Assertions.assertTrue(e instanceof IllegalArgumentException);
8787
}
8888
}
8989

9090
@Test
9191
public void testGetCollection() {
9292
Collection collection = yamlUtils.getCollection(properties, "collection");
93-
Assert.assertNotNull(collection);
93+
Assertions.assertNotNull(collection);
9494
properties.put("collection", null);
9595
try {
9696
yamlUtils.getBoolean(properties, "collection");
9797
} catch (Exception e) {
98-
Assert.assertTrue(e instanceof IllegalArgumentException);
98+
Assertions.assertTrue(e instanceof IllegalArgumentException);
9999
}
100100
}
101101

102102
@Test
103103
public void testGetStringList() {
104104
List<String> collection = yamlUtils.getStringList(properties, "collection");
105-
Assert.assertNotNull(collection);
105+
Assertions.assertNotNull(collection);
106106
try {
107107
yamlUtils.requireMap(Arrays.asList(1, 2), "key");
108108
} catch (Exception e) {
109-
Assert.assertTrue(e instanceof IllegalArgumentException);
109+
Assertions.assertTrue(e instanceof IllegalArgumentException);
110110
}
111111
}
112112
}

trpc-container/trpc-container-default/src/test/java/com/tencent/trpc/container/config/system/EnvironmentConfigurationTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
import com.tencent.trpc.container.config.ApplicationConfigParser;
44
import com.tencent.trpc.core.extension.ExtensionLoader;
5-
import org.junit.After;
6-
import org.junit.Assert;
7-
import org.junit.Before;
8-
import org.junit.Test;
5+
import org.junit.jupiter.api.AfterEach;
6+
import org.junit.jupiter.api.Assertions;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
99

1010
public class EnvironmentConfigurationTest {
1111

1212
private Environment environment;
1313

14-
@Before
14+
@BeforeEach
1515
public void init() {
1616
System.setProperty("global.namespace", "${env_type_enhancer}");
1717
System.setProperty("server.app", "wechat");
@@ -34,7 +34,7 @@ public void init() {
3434
environment = new Environment(parser);
3535
}
3636

37-
@After
37+
@AfterEach
3838
public void teardown() {
3939
System.clearProperty("global.namespace");
4040
System.clearProperty("server.app");
@@ -57,6 +57,6 @@ public void teardown() {
5757
@Test
5858
public void testGetInternalProperty() {
5959
Object internalProperty = environment.getInternalProperty("server.app");
60-
Assert.assertEquals(internalProperty, "wechat");
60+
Assertions.assertEquals(internalProperty, "wechat");
6161
}
62-
}
62+
}

0 commit comments

Comments
 (0)