19

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.

sibidiba
  • 6,270
  • 7
  • 40
  • 50
  • 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 Nov 20 '13 at 18:28

5 Answers5

23

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

luis
  • 231
  • 2
  • 3
11

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.

Graham Russell
  • 997
  • 13
  • 24
Dharshana
  • 1,212
  • 1
  • 9
  • 18
  • 1
    Listing hundreds of packages and thousand of classes is certainly something I do not intend to do. Why on earth would I? It is redundant information. Maven+TestNG can find all tests by default, Why is this feature lost when specifying a suite? (With the only intention of adding parameters...) – sibidiba Sep 18 '12 at 09:24
  • 3
    Your package names can be regular expressions, will will allow you to run everything. It's pretty expensive, though, since TestNG has to walk your entire class path to do that. – Cedric Beust Sep 18 '12 at 15:54
  • Exactly what I'm looking for. Why does class="\*" doesn't work then? (Walking through the class path isn't expensive as it happens only once at startup. Listing each class/package by hand *is* expensive and error prone.) – sibidiba Sep 19 '12 at 14:52
4

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.
Nathan
  • 8,093
  • 8
  • 50
  • 76
nighteblis
  • 93
  • 9
  • From the testing I've just done, the following would also work: ` ` – Dave Birch Dec 17 '15 at 14:32
  • thank Dave , seemed it is regular expression not simple wildcard. Just like luis said, .* match all . so com.* will match any under com.abc also comabc.abc (just guess) – nighteblis Jan 12 '16 at 16:39
1

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.

niharika_neo
  • 8,441
  • 1
  • 19
  • 31
  • How is this customsuite.xml designed by TestNG when I click on the package? – R11G Oct 13 '13 at 07:47
  • Yeah. I think you answered it. The customsuite xml is designed based on the plugins code. Specifically which plugin are we talking about here? – R11G Oct 13 '13 at 14:07
  • The testng plugin for eclipse, which gives you the options that you see when you right click. – niharika_neo Oct 14 '13 at 07:16
0

Below Works From 3 Level Pkg at TestNg

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