【问题标题】:How to run a test class from multiple classes in a TestNG suite xml file using maven?如何使用 maven 从 TestNG 套件 xml 文件中的多个类运行测试类?
【发布时间】:2018-03-03 09:06:27
【问题描述】:

我的问题实际上与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>

【问题讨论】:

  • 我相信我们不能这样做,因为它违背了拥有测试套件的目的。如果我们必须这样做,我们必须在代码中明确处理要执行哪个类。但不确定我是否正确。

标签: maven jenkins testng


【解决方案1】:

这是因为 -Dtest 覆盖了 -DsuiteFile(-Dtest 还覆盖了 testng.xml 中的“include”和“exclude”方法)。 因此,“clean test -DsuiteFile=Suites\Jquery.xml -Dtest=WebGuru99_2”将始终运行 WebGuru99_2 测试,而 -DsuiteFile 将被忽略。

我怀疑“clean test -Dtest=WebGuru99_2”是否会运行,因为您必须按照 pom 中的配置提供 -DsuiteFile=Suites\Jquery.xml

【讨论】:

  • 是的 'clean test -Dtest=WebGuru99_2' 现在不起作用,因为我已经在 pom 中将它作为变量给出,但如果我在那里放一个 suitfile 名称,这将起作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-24
  • 2012-09-23
  • 2018-11-06
  • 2016-02-20
  • 2019-05-08
  • 1970-01-01
相关资源
最近更新 更多