我正在使用maven 3.5.4,maven-surefire-plugin 2.19(我也尝试过maven-surefire-plugin 2.22-相同的结果)。 这是我的POM的构建部分:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<inherited>true</inherited>
<configuration>
<parallel>classes</parallel>
<threadCount>20</threadCount>
</configuration>
<executions>
<execution>
<id>default-test</id>
<configuration>
<excludedGroups>switch-enabled</excludedGroups>
</configuration>
</execution>
<execution>
<id>other-tests</id>
<configuration>
<groups>switch-enabled</groups>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我有两组需要单独运行的单元测试(由于有一个布尔值静态变量,因此我建立了一个TestNG组,并将所有需要在该组中打开开关的测试)。
Surefire仅运行“默认测试”执行,而忽略其他执行。我也尝试了以下方法,但它也无法正常工作-并未运行任何测试:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<inherited>true</inherited>
<configuration>
<parallel>classes</parallel>
<threadCount>20</threadCount>
</configuration>
<executions>
<execution>
<id>default-test</id>
<configuration>
<skip>true</skip>
</configuration>
</execution>
<execution>
<id>true-tests</id>
<configuration>
<groups>switch-enabled</groups>
</configuration>
</execution>
<execution>
<id>false-tests</id>
<configuration>
<excludedGroups>switch-enabled</excludedGroups>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
我做错了什么?
答案 0 :(得分:1)
surefire插件也有同样的问题。我建议您将测试运行配置移至testng .xml文件,该文件将分别运行每个集合,并且还允许您为每个配置并行运行:
<suite name="Test-Suite">
<test name="Test first set" parallel="20" preserve-order="true">
<classes>
<class name="domain.tests.com.TestA"/>
<class name="domain.tests.com.TestB"/>
// Classes of first set here..
</classes>
</test>
<test name="Test second set" parallel="20" preserve-order="true">
<classes>
<class name="domain.tests.com.TestC"/>
<class name="domain.tests.com.TestD"/>
// Classes of second set here..
</classes>
</test>
</suite>
答案 1 :(得分:1)
我最终使用了@AutomatedOwl建议的XML文件方法。我必须创建一个名为“ integration”的新组,该组在类级别上适用于集成测试类,因为没有直接的方法可以在TestNG XML中排除类,并且我不希望集成测试在surefire上运行测试阶段。这是我的TestNG XML:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestAll">
<test name="falseTest" parallel="classes" thread-count="20">
<groups>
<run>
<exclude name="switch-enabled" />
<exclude name="integration" />
</run>
</groups>
<packages>
<package name="com.somecomp" />
</packages>
</test>
<test name="trueTest" parallel="classes" thread-count="20">
<groups>
<run>
<include name="switch-enabled" />
<exclude name="integration" />
</run>
</groups>
<packages>
<package name="com.somecomp" />
</packages>
</test>
</suite>
这是我的POM的构建部分:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<inherited>true</inherited>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>