注意
不太确定为什么这个问题不能总是重现,以及为什么显然(基于strack跟踪)测试在TestNG的XmlSuite类中返回null。即使不使用任何自定义侦听器,也会出现问题
用于surefire和testng的POM.xml配置:
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.0.0-beta1</version>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<!--<excludes> <exclude>**/integration/*Test.java</exclude> </excludes>
<suiteXmlFiles> <suiteXmlFile>src/test/resources/suite.xml</suiteXmlFile>
</suiteXmlFiles> -->
<skip>true</skip>
<argLine>-Xms4096m</argLine>
<systemProperties>
<property>
<name>app.env</name>
<value>${app.env}</value>
</property>
</systemProperties>
<workingDirectory>./</workingDirectory>
<reportsDirectory>${user.home}/report/reports_${report.directory}/</reportsDirectory>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<properties>
<property>
<name>usedefaultlisteners</name>
<value>false</value>
</property>
<property>
<name>listener</name>
<value></value>
</property>
</properties>
<skip>false</skip>
<excludes>
<exclude>none</exclude>
</excludes>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/${test.suite}</suiteXmlFile>
</suiteXmlFiles>
<printSummary>false</printSummary>
</configuration>
</execution>
</executions>
</plugin>
Suite.XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Failed suite" parallel="tests" thread-count="5" verbose="3">
<test name="Test1" preserve-order="true">
<parameter name="country" value="us" />
<parameter name="language" value="en" />
<parameter name="env" value="" />
<parameter name="browser" value="" />
<classes>
<class name="com.test.tests">
<methods>
<include name="test1" />
</methods>
</class>
</classes>
</test>
<test name="Test2" preserve-order="true">
<parameter name="country" value="us" />
<parameter name="language" value="en" />
<parameter name="env" value="" />
<parameter name="browser" value="" />
<classes>
<class name="com.test.tests">
<methods>
<include name="test2" />
</methods>
</class>
</classes>
</test>
<test name="Test3" preserve-order="true">
<parameter name="country" value="us" />
<parameter name="language" value="en" />
<parameter name="env" value="" />
<parameter name="browser" value="" />
<classes>
<class name="com.test.tests">
<methods>
<include name="test3" />
</methods>
</class>
</classes>
</test>
<test name="Test4" preserve-order="true">
<parameter name="country" value="us" />
<parameter name="language" value="en" />
<parameter name="env" value="" />
<parameter name="browser" value="" />
<classes>
<class name="com.test.tests">
<methods>
<include name="test4" />
</methods>
</class>
</classes>
</test>
<test name="Test5" preserve-order="true">
<parameter name="country" value="us" />
<parameter name="language" value="en" />
<parameter name="env" value="" />
<parameter name="browser" value="" />
<classes>
<class name="com.test.tests">
<methods>
<include name="test5" />
</methods>
</class>
</classes>
</test>
</suite>
完整堆栈跟踪
java.lang.NullPointerException
at org.testng.xml.XmlSuite.getAllParameters(XmlSuite.java:434)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:367)
at org.testng.SuiteRunner.run(SuiteRunner.java:302)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:96)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1145)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1067)
at org.testng.TestNG.runSuites(TestNG.java:997)
at org.testng.TestNG.run(TestNG.java:965)
at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:283)
at org.apache.maven.surefire.testng.TestNGXmlTestSuite.execute(TestNGXmlTestSuite.java:75)
at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:120)
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:384)
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:345)
at org.apache.maven.surefire.booter.ForkedBooter.execute(ForkedBooter.java:126)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:418)