JUnit4 的maven 依赖为
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
JUnit5 的 maven 依赖为
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
使用 MAVEN PACKAGE打包时,JUnit4可以在打包时运行全部测试用例,而JUnit5不会运行。
这是因为现在 maven 并不能直接识别JUnit5测试用例,需要在插件中添加 maven surefire
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
再次执行 mvn package,可以看到打包的时候运行了测试用例。