简体   繁体   English

如何告诉Maven和TestNG运行特定的测试类或suite.xml文件?

[英]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: 同样,我想:

  • Specify a single test class (with a bunch of parameters at the command line) 指定一个测试类(在命令行中带有一堆参数)
  • Specify a testng XML file containing a bunch of test classes and different parameters. 指定一个包含一堆测试类和不同参数的testng XML文件。

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.

相关问题 如何在Testng中查找Test suite.xml执行状态 - How to find Test suite.xml execution status in Testng Maven surefire 插件无法选择正确的 testng suite.xml 文件 - Maven surefire plugin fails to pick correct testng suite.xml file 一旦将新的Scala类添加到suite.xml文件中,TestNG就无法在类路径中找到类 - TestNG Cannot find class in classpath once a new scala class is added to the suite.xml file 如何执行 java class 并使用 POM.xml 文件运行所有套件。 - How to execute java class and the run all the suite.xml files using POM.xml 需要通过Main.class运行suite.xml - Need to run suite.xml through Main.class 我们如何在testNg suite.xml中创建对多个测试的依赖 - How can we create dependency on several tests in testNg suite.xml 如何在testng的单个套件中多次运行测试类 - How to run a test class more than once in a single suite in testng 无法在Maven项目中运行TestNG Test Suite - Can't run TestNG Test Suite in a maven project 从可运行的jar中运行TestNG XML套件,其中包含特定文件夹中的测试类 - Run TestNG XML suite from runnable jar with test classes in specific folder TestNG类可以并行运行,但方法不能并行运行。 如何配置testng.xml文件和测试类,以便方法也可以并行运行? - TestNG classes run in parallel, but methods don't. How do I configure my testng.xml file and test classes so methods will also run in parrallel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM