views:

1054

answers:

4

I have a TestNG suite with large amount of methods. I execute this suite using wrapper built on top of TestNG runner. All tests in the suite fail except one. What should I write in testng.xml to execute just that one failed test?

Obvious solution is to assign unique group names to all of the methods and then specify name in testng.xml. This can work in case of 2-3 methods, but it gets harder as number of tests grow.

A: 

There are several methods to do this.

Are you using Eclipse for development? There is an Eclipse plugin for TestNG and I think it would be by far the easiest way for you to run specific tests. The plugin allows you to run suite, group, class or method of available test.

If not, I believe you can setup an ant task for launching the test(http://testng.org/doc/ant.html) and use attributes like "classfilesetref" to provide a list of test to run. You can specify the test in a separate file so you don't have to update the build.xml every time your run the test.

blissfool
First option is not available - I am using wrapper, built on top of TestNG runner to launch tests. Eclipse does not catch tests results, executed by my wrapper.Thanks for the second option - I will try it.
Glorphindale
A: 

After each run, TestNG creates a filed called testng-failed.xml that contains only the tests that failed. Just invoke TestNG again on that file:

java org.testng.TestNG testng.xml java org.testng.TestNG testng-failed.xml

(replace org.testng.TestNG with your own runner since you seem to use a customized one).

Cedric Beust
+1  A: 

You could also create your own ITestListener (since you've got your own wrapper anyhow) that keeps track of the failures and then from that generate your own failures suite file that contains only the failed test. TestNG's listener/interceptor hooks are pretty good. At work we've extended TestNG using them several ways:

  • capture/playback of generated data sets
  • result logging to a database
  • customized test output (logs)
  • meta data such as IDs, descriptions, for data sets provided by a @DataProvider
  • runtime checks of environment dependent restrictions on test cases
Jeremy Raymond
A: 

try this:

  <classes>
    <class name="test.IndividualMethodsTest">
      <methods>
        <exclude name="testMethod" />
      </methods>
    </class>
  </classes>
Pierre Gardin