运行 testng xml 时,它只运行指定的测试(即,下面示例中的 a-t1、a-t3)。
有关更多信息,请参阅https://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html中的“在测试标签中运行 'testnames'”部分。
</plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
[...]
<suiteXmlFiles>
<file>src/test/resources/suite.xml</file>
</suiteXmlFiles>
<properties>
<property>
<name>testnames</name>
<value>a-t1,a-t3</value>
</property>
</properties>
[...]
</configuration>
</plugin>
[...]
</plugins>
当使用这些标签从 Eclipse 运行单个测试时,出现异常。
[RemoteTestNG] detected TestNG version 7.0.0
org.testng.TestNGException:
The test(s) <[a-t1,a-t3]> cannot be found.
at org.testng.TestNG.parseSuite(TestNG.java:315)
at org.testng.TestNG.initializeSuitesAndJarFile(TestNG.java:350)
at org.testng.TestNG.initializeEverything(TestNG.java:980)
at org.testng.remote.support.RemoteTestNG6_12.initialize(RemoteTestNG6_12.java:22)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:98)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
为了避免上述异常,我应该注释掉surefire插件的属性标签。
有没有办法避免异常而不必注释掉surefire插件的属性标签?
<properties>
<property>
<name>testnames</name>
<value>a-t1,a-t3</value>
</property>
</properties>