我在我的pom中使用TestNg确定了以下配置:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<skipTests>${skip-all-tests}</skipTests>
</configuration>
<executions>
<execution>
<id>unit-tests</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>${skip-unit-tests}</skip>
<groups>unit</groups>
<excludedGroups>integration</excludedGroups>
</configuration>
</execution>
<execution>
<id>integration-tests</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>${skip-integration-tests}</skip>
<groups>integration</groups>
<excludedGroups>unit</excludedGroups>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
但似乎两次执行总是先于"默认测试"运行,它似乎运行每个@test注释方法(至少我认为是这样).
--- maven-surefire-plugin:2.12:test (default-test) @ my-project
Run Code Online (Sandbox Code Playgroud)
例如,在项目上运行"mvn test",就会发生两次测试."默认测试"和"单元测试".
有人可以向我解释一下吗?这可以被禁用或控制(配置什么是测试的,什么不是)?
贝娄我的实际pom的一部分.已经在@Test注释中为集成测试的Testng测试分配了一个"集成"组.为了做一点测试,我没有在测试阶段排除"集成"组.
使用例如mvn verify或mvn install进行构建时,集成测试将在测试阶段执行,但不会在验证阶段或集成测试阶段执行.测试的次数仍为0.不知怎的,它们没有被提取.任何人都知道什么可能是错的?
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.1</version>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12.1</version>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<skip>false</skip>
<excludedGroups>unit</excludedGroups>
</configuration>
</execution>
<execution>
<id>verify</id>
<phase>verify</phase>
<goals>
<goal>verify</goal>
</goals>
<configuration>
<skip>false</skip>
<excludedGroups>unit</excludedGroups>
</configuration>
</execution>
</executions>
<configuration>
<skip>false</skip>
<excludedGroups>unit</excludedGroups>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
更新:添加TestNG作为故障安全插件的依赖项没有帮助
integration testng maven maven-surefire-plugin maven-failsafe-plugin