如何使用maven从TestNG套件xml文件中的多个类运行测试类?

时间:2018-03-03 09:06:27

标签: maven jenkins testng

我的问题实际上是How do I tell Maven and TestNG to run a specific test class and suite.xml file?的副本,但我不明白接受的答案,所以再问一遍。

我有同样的问题,当我尝试使用clean test -DsuiteFile=Suites\Jquery.xml运行特定套件时,它会运行该套件,这很好。同样clean test -Dtest=WebGuru99_2运行该测试类,但是当我尝试执行clean test -DsuiteFile=Suites\Jquery.xml -Dtest=WebGuru99_2时,它会运行该类,但它现在不依赖于套件文件。我可以在这里提供任何套件文件,它将运行相同的测试类,这违背了套件文件的目的。

的pom.xml

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <suiteFile></suiteFile>
  </properties>

  <dependencies>
   <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>2.35.0</version>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>2.35.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.17</version>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.17</version>
        </dependency>
  </dependencies>
  <build>
        <plugins>
        <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.18</version>
                <configuration>
                    <suiteXmlFiles>
                        <suiteXmlFile>${suiteFile}</suiteXmlFile>
                    </suiteXmlFiles>
                </configuration>
            </plugin>
        </plugins>
</build>

1 个答案:

答案 0 :(得分:0)

这是因为-Dtest覆盖-DsuiteFile(-Dtest还覆盖&#34; include&#34;以及#34;排除&#34; testng.xml中的方法)。 所以&#34;清理测试-DsuiteFile = Suites \ Jquery.xml -Dtest = WebGuru99_2&#34;将始终运行WebGuru99_2测试,并且将忽略-DsuiteFile。

我怀疑&#34;清洁测试-Dtest = WebGuru99_2&#34;将运行与否,因为您必须按照pom中的配置提供-DsuiteFile = Suites \ Jquery.xml

相关问题