如何告诉Maven和TestNG运行特定的测试类或suite.xml文件?
我正在使用Maven对网站运行TestNG集成测试。目前,我可以使用此命令来运行特定的测试类:
I am using Maven to run TestNG integration tests against a website. Currently, I can use this command to run a specific test class:
mvn -Dit.test="MyTestClassname" verify
我还希望能够指定一个TestNG套件XML文件来运行一堆类和特定的类参数。
I would also like to be able to specify a TestNG suite XML file to run a bunch of classes together with specific parameters.
我可以在我的POM中设置Failsafe插件以接受如下的suiteXmlFiles参数:
I can set up the Failsafe plugin in my POM to accept a suiteXmlFiles parameter like so:
<configuration>
<threadCount>1</threadCount>
<suiteXmlFiles>
<suiteXmlFile>${basedir}/src/test/resources/suites/${suiteFile}</suiteXmlFile>
</suiteXmlFiles>
<systemPropertyVariables>
<browser>${browser}</browser>
<environment>${environment}</environment>
<debugMode>${debugMode}</debugMode>
<caseId>${caseId}</caseId>
</systemPropertyVariables>
</configuration>
这让我发出这个命令:
mvn -DsuiteFile="MyTestSuite.xml"
但是现在我不能使用-Dit.test =MyTestClassname选项,因为Maven现在尝试传递一个空值作为套件名称。
But now I can't use the -Dit.test="MyTestClassname" option, because Maven is now trying to pass an empty value as the suite name.
有没有办法在这附近?同样,我想要:
Is there a way around this? Again, I want to either:
- 指定一个测试类(在命令行中有一堆参数)
- 指定包含一堆测试类和不同参数的testng XML文件。
我正在使用maven-surefire-plugin。它允许我运行suitefile和类。
这是我的surefire插件
I am using maven-surefire-plugin. It lets me run both suitefile and a class. This is my surefire plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
<skipTests>${skipTests}</skipTests>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
要运行套件文件,我使用
To run suitefile , I use
mvn test -DsuiteXmlFile=<suitefile>
要运行类文件,我使用
mvn test -Dtest=<qualified path of the test class>