[英]How do I tell Maven and TestNG to run either a specific test class or a suite.xml file?
I am using Maven to run TestNG integration tests against a website. 我正在使用Maven对一个网站运行TestNG集成测试。 Currently, I can use this command to run a specific test class: 当前,我可以使用此命令来运行特定的测试类:
mvn -Dit.test="MyTestClassname" verify
I would also like to be able to specify a TestNG suite XML file to run a bunch of classes together with specific parameters. 我还希望能够指定一个TestNG套件XML文件来运行带有特定参数的一堆类。
I can set up the Failsafe plugin in my POM to accept a suiteXmlFiles parameter like so: 我可以在POM中设置Failsafe插件以接受suiteXmlFiles参数,如下所示:
<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>
That lets me issue this command: 这让我发出以下命令:
mvn -DsuiteFile="MyTestSuite.xml"
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. 但是现在我不能使用-Dit.test =“ MyTestClassname”选项,因为Maven现在试图传递一个空值作为套件名称。
Is there a way around this? 有没有解决的办法? Again, I want to either: 同样,我想:
I am using maven-surefire-plugin. 我正在使用maven-surefire-plugin。 It lets me run both suitefile and a class. 它可以让我同时运行suitefile和一个类。 This is my surefire plugin 这是我的surefire插件
<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 要运行suitefile,我使用
mvn test -DsuiteXmlFile=<suitefile>
And to run a class file, I use 为了运行一个类文件,我使用
mvn test -Dtest=<qualified path of the test class>
The above method did not work for me. 上面的方法对我不起作用。 If you're also getting an error on your pom.xml when you pass ${suiteXmlFile}
or other issues as I was having: 如果在传递${suiteXmlFile}
或我遇到的其他问题时,pom.xml上也出现错误:
<suiteXmlFiles>
<suiteXmlFile>*ERROR*${suiteXmlFile}*ERROR*</suiteXmlFile>
</suiteXmlFiles>
Here is a better solution, at the command, cd to the location of your pom.xml file thenn run on command line: 这是一个更好的解决方案,在命令cd上运行在命令行上运行的pom.xml文件thenn的位置:
mvn test -Dsurefire.suiteXmlFiles=yourfileName(WithFullPathIfNotInRootDirectory).xml mvn test -Dsurefire.suiteXmlFiles = yourfileName(WithFullPathIfNotInRootDirectory).xml
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.