Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 216
Sad Developer Avatar asked Nov 04 '09 09:11

Sad Developer


People also ask

Can we execute multiple suites from a single TestNG xml file?

Yes, look up the <suite-files> tag in the testng. xml documentation.

Can we have 2 suites in TestNG xml?

TestNG gives an option to execute multiple test in parallel in a single configuration file (XML).

How do you run the same test suite multiple times in TestNG?

How to run same test multiple times using TestNG? First, create a TestNG class file and add all the required annotations. Identify that @Test annotation which you want to run multiple times. Once you identified the @Test annotation then design the test format as below.


3 Answers

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>
like image 52
smaant Avatar answered Oct 31 '22 14:10

smaant


Try this:

  <classes>
    <class name="test.IndividualMethodsTest">
      <methods>
        <exclude name="testMethod" />
      </methods>
    </class>
  </classes>
like image 30
Pierre Gardin Avatar answered Oct 31 '22 14:10

Pierre Gardin


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

like image 7
Cedric Beust Avatar answered Oct 31 '22 15:10

Cedric Beust