And*_*s_D 6 java junit testng maven jnario
有一段时间,可以配置maven surefire在一个构建中执行jUnit测试和testNG测试.我不会扩展我为什么这样做的原因(好的,提示:testNG是我们的标准框架,但是像jnario这样的框架需要jUnit).
一般的方法是配置如下所示的surefire插件:
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.version}</version>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${surefire.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-testng</artifactId>
<version>${surefire.version}</version>
</dependency>
</dependencies>
</plugin>
Run Code Online (Sandbox Code Playgroud)
这很有效,jUnit测试和testNG测试得到执行.
但是 - 现在我看到testNG也尝试执行jUnit测试(反之亦然) - 当然没有成功,因为它不会看到任何注释,但看起来它重新标记了测试"传递"...无论如何,一些报告工具不再显示jUnit测试中的测试失败,除非我评论第二个依赖项.
有没有更好的方法来配置surefire,以便两个框架的测试只能由他们的测试运行者执行?
和你有同样的问题.零会导致TestNG报告,但看起来像是运行了测试.最后通过两次单独执行来完成这项工作maven-surefire-plugin
dependencies从插件中删除该部分.
<testNGArtifactName>(我们将需要它),测试将由TestNG执行,并且将失败java.lang.NullPointerExceptionTestNg<executions>如下:<plugin>
<!-- configured to work with JUnit and TestNg in same project separatelly -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- whatever you need... -->
<!-- skip the default execution, we have separate for Ng and for JUnit -->
<skip>true</skip>
</configuration>
<executions>
<execution>
<id>TestNg-execution</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<!-- overwrite skip from default config -->
<skip>false</skip>
<includes>
<include>%regex[.*TestNg.*]</include>
</includes>
<!-- used to skip JUnit profider -->
<junitArtifactName>dev:null</junitArtifactName>
<!-- to continue on next execution in case of failures here -->
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</execution>
<execution>
<id>JUnit-execution</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<!-- used to skip TestNg profider -->
<testNGArtifactName>dev:null</testNGArtifactName>
<excludes>
<exclude>%regex[.*TestNg.*]</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
经测试:
<junit-version>4.11</junit-version>
<maven-surefire-plugin-version>2.16</maven-surefire-plugin-version>
<org.testng-version>6.8.7</org.testng-version>
Run Code Online (Sandbox Code Playgroud)
这个配置来自以下方面的想法:
在一次运行中使用Maven Surefire运行TestNG-,JUnit3-和JUnit4-测试,
您的SUREFIRE错误报告,surefire
插件配置
希望能帮助到你.
| 归档时间: |
|
| 查看次数: |
4941 次 |
| 最近记录: |