0

In TestNG 6.3.1~6.9.10, I'm trying to create dependency between two classes like below.

class A {
    @Test(groups={"GA"})
    public void testA() {
    }
}

class B {
    @Test(groups={"GB"}, dependsOnGroups={"GA"})
    public void testB() {
    }
}

It works if I just list classA&B in in testng.xml.

<classes>
    <class name="pkg.A"></class>
    <class name="pkg.B"></class>
</classes>

If I want to only pick out testcases belong to "GB" and expect the same behavior to previous one,

<groups>
    <run>
        <include name="GB" />
    </run>
</groups>
<classes>
    <class name="pkg.A"></class>
    <class name="pkg.B"></class>
</classes>

then TestNg complains

DependencyMap::Method "B.testB()[pri:0, instance:pkg.B@250970c1]" depends on nonexistent group "GA".

Why does not TestNg recognize group GA? How to pick out some groups of testcases to run while keeping group dependencies? Thank you in advance.

ShenLei
  • 567
  • 1
  • 5
  • 17

2 Answers2

0

The TestNG dependsOn* is only used to order tests for a specific run.

testng.xml is used to select tests for a specific run.

If you don't specify everything you want, dependsOn* may be ignored because tests are already well ordered.

When you don't specify a group, all are actives.

Check the documentation for more details.

juherr
  • 5,640
  • 1
  • 21
  • 63
  • Thank you very much. For clarity, Suppost there are 3 classes A,B,C belongs to 3 groups GA,GB,GC respectively. GB and GC both depend on GA. I would like to select only GA and GB to run. Could you give me an example of testng.xml for such case? – ShenLei Jun 21 '16 at 07:13
  • Did you try with exclusions instead of inclusions ? – juherr Jun 21 '16 at 09:03
  • Ok, and is it a problem to specify all groups you want (by listing them or using regex)? That's the last solution I see. – juherr Jun 21 '16 at 11:47
0

This behavior is as per TestNG design. TestNG considers hard dependency if you haven't provided alwaysRun=true. In case of hard dependency the run configuration must include methods/groups on which it depending upon. Please refer dependency documentation.

user861594
  • 5,733
  • 3
  • 29
  • 45
  • Thank you very much. For clarity, suppost there are 10 classes Base,C1,C2..C9 belongs to 10 groups GBase,G1,G2..G9 respectively. G1..9 are all depends on GBase. I would like to select only GBase and G1 to run. Could you give me an workable example of testng.xml for such case, which does not trigger DependencyMap::Method error? – ShenLei Jun 21 '16 at 11:43
  • Why are you using groups here if 1 specific group <=> 1 specific class? Just use and `dependsOnMethods` (which is supposed to work with methods from other classes too). – juherr Jun 21 '16 at 11:51
  • Just for simulating a tree-like group dependency, and try to find a way to run testng on only one branch. On the other hand, dependsOnMethods does not work between classes: http://stackoverflow.com/questions/7692129/testng-dependsonmethods-from-different-class – ShenLei Jun 22 '16 at 02:13