17
votes

Just about to implement a test framework with Maven+TestNG+Selenium.

How do you declare a suite.xml that tells TestNG to run ALL tests? I've tried all these to no avail:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Toplevel TestNG configuration" verbose="10">
  <test name="all">
    <classes>
      <class name="*" />
    </classes>
  </test>
</suite>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Toplevel TestNG configuration" verbose="10">
  <test name="all">
    <groups>
      <run>
        <include name="*" />
        <exclude name="disabled" />
      </run>
    </groups>
  </test>
</suite>

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Toplevel TestNG configuration" verbose="10">
  <test name="all">
    <packages>
      <package name="*" />
    </packages>
  </test>
</suite>

I need to specify different suite configurations with different paramers but all running all tests. Every example I could dig up explicitely lists each class or package which makes less than zero sense to me.

5
I similarly find this truly bizarre. It appears not only possible, but easy to create a TestNG test in a test directory as one would expect, but fail to update testng.xml and lo and behold, the test isn't actually being run as part of the suite... - dimo414

5 Answers

22
votes

Should use .* to match them all as far as I know.

10
votes

You can add all test classes inside a package by declaring testng.xml file as

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="sampleTest" parallel="false">

    <test name="sample-Test" preserve-order="true" verbose="2">
        <packages>
            <package name="org.sample.something.*"/>
        </packages>
    </test>

</suite>

There is nowhere to pass tests as search options. If you want to do something like that you have to implement the suite in code and implement search scenario there.

4
votes

Assume you have a three level package, your test classes are under the com.abc.xyz package.

<package name="*" /> </packages> , doesn't work. 
<package name="com.*.*" />  doesn't work. 
<package name="com.abc.*" />  does work.
1
votes

AFAIK testng doesn't have an option of regex like you are looking for.

But, I think you can get what you want in two ways :

  1. If you are working on Eclipse with the Testng plugin. You can just select your test folder which has all the packages defined. With maven it would mostly be your src/test/java folder, right click and say run as testng. What this would do is it would create a temporary customsuite.xml which would have all your classes listed. You can save the xml as your default xml.

  2. The surefire plugin with maven has an option of specifying includes and then a pattern. You can try setting it to */.java which I think would pickup all testcases (not tried though). You can invoke your tests as mvn test then.

0
votes

Below Works From 3 Level Pkg at TestNg

<package name="orgPkg.namePkg.appnamePkg.applicationPkg.functionalityPkg"/></packages>