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

11,658

Solution 1

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>

Solution 2

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

Share:
11,658

Related videos on Youtube

Daryl Spitzer
Author by

Daryl Spitzer

Father of three, husband, computer programmer (Pythonista), skeptic, atheist, podcast listener, baseball fan, Canadian (in the United States).

Updated on May 01, 2022

Comments

  • Daryl Spitzer
    Daryl Spitzer about 2 years

    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?