How to execute one test from large TestNG suite using testng.xml?

56,077

Solution 1

Instead of exclude, you may use include. It'll exactly what you want. Only this test will be executed.

  <classes>
    <class name="test.IndividualMethodsTest">
      <methods>
        <include name="testMethod" />
      </methods>
    </class>
  </classes>

Solution 2

Try this:

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

Solution 3

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).

Solution 4

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.

For installing testng Plugin.Just Follow the steps: 1-Go to "Help" Menu in Eclipse. 2-Select "Install New Software"". 3-Add"http://beust.com/eclipse."

It works in case of the error you specified I think you do not have the plugin installed within the Eclippse IDE

Solution 5

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
Share:
56,077

Related videos on Youtube

Sad Developer
Author by

Sad Developer

Updated on July 09, 2022

Comments

  • Sad Developer
    Sad Developer almost 2 years

    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.

  • Sad Developer
    Sad Developer over 14 years
    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.
  • David Blevins
    David Blevins almost 13 years
    Or <include name="testMethod"/> to execute just the one
  • Om Sao
    Om Sao over 6 years
    Can't believe, Beust himself replying answer!!