Daryl Spitzer
Daryl Spitzer

Reputation: 149324

How do I have TestNG run tests in specific groups (from the command-line)?

I'm invoking TestNG from the command-line like this:

java org.testng.TestNG -groups "foo" testng.xml

...with the intention of only running tests annotated with:

@Test(groups = { "foo" })

...but it's running all my tests. Do I need to change my testng.xml file?

<suite name="BarSuite" verbose="1">
  <test name="AllInPackage">
    <packages>
      <package name="com.example.bar"/>
   </packages>
 </test>
</suite>

Is TestNG ignoring the -groups command-line argument because testng.xml says to run all the tests in the package? If so, how should I change my testng.xml file?

Upvotes: 6

Views: 14810

Answers (2)

Victor Kondin
Victor Kondin

Reputation: 51

Java:
Running tests with TestNG in specific groups is very easy:
1) Open you project folder in command line
example: cd C:\FunctionalTests
2) Run test by group

mvn test -Dgroups=group1,group2

group1, group2 - name of the test group
example in java

NB!
mvn test command works, if your project building manager is maven.
If you dont know, what kind of building manager you are using, you can verify it by checking (i.e) pom.xml existence in your project

Upvotes: 4

Cedric Beust
Cedric Beust

Reputation: 15608

You got it exactly right: if you specify a testng.xml, it takes precedence over the command line switches.

Just add the following to your XML file:

  <groups>
    <run>
      <include name="foo"  />
    </run>
  </groups>

Upvotes: 5

Related Questions