views:

25

answers:

1

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?

+1  A: 

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>
Cedric Beust
That worked. But don't I have to specify a testng.xml file? Can I modify my testng.xml file so can use the -groups command-line option (instead of having a separate testng.xml file for each subset of groups I want to run)?
Daryl Spitzer