TestNG surefire, run suite with maven command line
Asked Answered
H

3

10

Is it possible to run a predefined xml suite from the command line through maven?

I am able to run a class or a particular test. But I am unable to run a suite.

Here is what I am running from the command line: -->

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

I do have a suite defined, which runs nicely through intelliJ, but I am not sure how to invoke the suite.xml file.

Or for example, after the tests have run, testng creates a testng-failed file which is setup to run all the failed tests again.

Using mvn, how would I kick off this test suite.

Hus answered 30/4, 2012 at 22:19 Comment(1)
I found the answer here: #11763301Hairless
A
21

This answer gave me what I was looking for, namely the ability to pass at the command line the name of the suite I want to run:

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

In a nutshell, add the following to the maven-surfire-plugin stanza of your pom.xml:

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

Then you can specify the desired testng suite xml file at the command line:

mvn clean install test -DsuiteXmlFile=testngSuite.xml
Assure answered 6/10, 2014 at 17:39 Comment(0)
T
9
<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>

it worked for me.

Tallent answered 12/10, 2012 at 5:10 Comment(0)
C
6

Usually you don't need nothing special in relationship with TestNG. Just use the maven-surefire-plugin:

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

and based on that all Tests which are correctly annotated should run. Ah of course you need a dependency to TestNG like this:

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

Usually i wouldn't create Test Suites anymore, cause this a point which you have to maintain which is often missed to update etc. just use annotations.

If you need to run a particular suite of tests just define a testng.xml file in src/test/resources and enhance the configuration of the maven-surefire plugin appropriately.

  <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>
Cleland answered 1/5, 2012 at 9:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.