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

时间:2015-03-24 21:34:59

标签: java xml maven testng

我正在使用Maven对网站运行TestNG集成测试。目前,我可以使用此命令来运行特定的测试类:

mvn -Dit.test="MyTestClassname" verify

我还希望能够指定一个TestNG套件XML文件来运行一堆类和特定参数。

我可以在我的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>

这让我发出这个命令:

mvn -DsuiteFile="MyTestSuite.xml"

但现在我无法使用-Dit.test =&#34; MyTestClassname&#34;选项,因为Maven现在尝试将空值作为套件名称传递。

有解决方法吗?同样,我想要:

  • 指定单个测试类(在命令行中包含一堆参数)
  • 指定包含一堆测试类和不同参数的testng XML文件。

2 个答案:

答案 0 :(得分:3)

我正在使用maven-surefire-plugin。它允许我运行suitefile和类。 这是我的万无一失的插件

<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>

要运行suitefile,我使用

mvn test -DsuiteXmlFile=<suitefile>

要运行类文件,我使用

mvn test -Dtest=<qualified path of the test class>

答案 1 :(得分:0)

上述方法对我不起作用。如果您在传递${suiteXmlFile}或其他问题时也在pom.xml上收到错误:

  <suiteXmlFiles>
     <suiteXmlFile>*ERROR*${suiteXmlFile}*ERROR*</suiteXmlFile>
  </suiteXmlFiles>

这是一个更好的解决方案,在命令中,cd到你的pom.xml文件的位置然后在命令行上运行:

  
    
      

mvn test -Dsurefire.suiteXmlFiles = yourfileName(WithFullPathIfNotInRootDirectory).xml

    
  
相关问题