Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 369
Daryl Spitzer Avatar asked Aug 19 '10 21:08

Daryl Spitzer


1 Answers

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>
like image 138
Cedric Beust Avatar answered Oct 13 '22 22:10

Cedric Beust