【发布时间】:2020-01-22 17:32:38
【问题描述】:
我正在为一个已经有一些 TestNG 测试的项目编写单元测试。由于我使用 JUnit Jupiter(又名 JUnit 5)来编写新测试,我观察到当我执行“mvn clean verify”时仅运行 TestNG 测试的问题
以下是我在pom.xml 中的依赖项
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>3.2.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>2.23.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.6.0</version>
<scope>test</scope>
</dependency>
由于 2.22.0 以后的surefire插件提供了JUnit 5支持,下面是我的surefire插件部分
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
有什么方法可以让我同时保留在项目中并能够通过 maven 运行所有测试?这是必要的,以便代码覆盖率报告将所有测试一起显示。
我还注意到,如果我在老式引擎依赖的帮助下使用 JUNIT 4 测试,所有测试(JUnit + TestNG)都会通过 maven 一起运行。我很困惑为什么 JUnit 5 不会发生这种情况。
【问题讨论】:
-
根据文档maven.apache.org/surefire/maven-surefire-plugin/examples/…“TestNG 6.5.1 及更高版本提供了在当前 Maven 项目中运行 TestNG 和 JUnit 4.x 的支持”。不支持 Junit 5
标签: unit-testing junit testng junit5 maven-surefire-plugin