【问题标题】:TestNG surefire, run suite with maven command lineTestNG 万无一失,使用 maven 命令行运行套件
【发布时间】:2012-05-10 14:28:19
【问题描述】:

是否可以通过 maven 从命令行运行预定义的 xml 套件?

我能够运行一个课程或一个特定的测试。但我无法运行套件。

这是我从命令行运行的: -->

 mvn -Dtest=TestCircle#mytest -Denvironment=test -Dbrowser=firefox -DscreenShotDirectory=/Users/jeremy/temp test

我确实定义了一个套件,它可以通过 intelliJ 很好地运行,但我不确定如何调用 suite.xml 文件。

或者例如,在测试运行后,testng 创建一个 testng-failed 文件,该文件被设置为再次运行所有失败的测试。

使用 mvn,我将如何启动这个测试套件。

【问题讨论】:

标签: testing selenium-webdriver maven-2 testng surefire


【解决方案1】:

这个答案给了我我一直在寻找的东西,即能够在命令行中传递我想要运行的套件的名称:

http://www.vazzolla.com/2013/03/how-to-select-which-testng-suites-to-run-in-maven-surefire-plugin/

简而言之,将以下内容添加到 pom.xml 的 maven-surfire-plugin 节中:

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

然后你可以在命令行指定想要的testng套件xml文件:

mvn clean install test -DsuiteXmlFile=testngSuite.xml

【讨论】:

    【解决方案2】:
    <build>
     <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.12</version>
        <configuration>
          <suiteXmlFiles>
            <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
          </suiteXmlFiles>
        </configuration>
      </plugin>
    </build>
    

    它对我有用。

    【讨论】:

      【解决方案3】:

      通常你不需要任何与 TestNG 的特殊关系。只需使用 maven-surefire-plugin:

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.12</version>
        </plugin>
      

      并基于此,所有正确注释的测试都应该运行。啊,你当然需要像这样对 TestNG 的依赖:

      <dependency>
        <groupId>org.testng</groupId>
        <artifactId>testng</artifactId>
        <version>6.5.2</version>
        <scope>test</scope>
      </dependency>
      

      通常我不会再创建测试套件,因为这是您必须维护的点,经常错过更新等。只需使用注释。

      如果您需要运行特定的测试套件,只需在 src/test/resources 中定义一个 testng.xml 文件并适当地增强 maven-surefire plugin 的配置。

        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.12</version>
          <configuration>
            <suiteXmlFiles>
              <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
            </suiteXmlFiles>
          </configuration>
        </plugin>
      

      【讨论】:

        猜你喜欢
        • 2018-08-05
        • 2018-08-16
        • 1970-01-01
        • 2015-11-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-02
        相关资源
        最近更新 更多