0

I want to be as flexible as possible with my test suites - I want to be able to:

  • run all tests by priority (p1, p2...) - this is easy
  • run all tests by module (module1, module2...) - this is easy
  • run tests that are a specific priority and specific module - I can't figure out

I have some tests thusly:

@Test(groups = {"p1", "module1"})
public void p1module1() {
    System.out.println("p1module1");
}
@Test(groups = {"p2", "module1"})
public void p2module1() {
    System.out.println("p2module1");
}
@Test(groups = {"p1", "module2"})
public void p1module2() {
    System.out.println("p1module2");
}
@Test(groups = {"p2", "module2"})
public void p2module2() {
    System.out.println("p2module2");
}

But if I do something like this

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="qa-selenium">
    <test name="My Suite">
        <groups>
            <run>
                <include name="p1"/>
                <include name="module1"/>
            </run>
        </groups>
        <packages>
            <package name="com.mycompany.qa.selenium.*"/>
        </packages>
    </test>
</suite>

the includes are treated like an OR, but I want an AND. In this case I want to create a suite that ONLY executes p1module1()

I realize I could use tons of excludes - in this example

<exclude name="p2"/>
<exclude name="module2"/>

but I really want to avoid this. Is there a way to do this, preferably without metaprogramming?

jwallis
  • 75
  • 1
  • 9

2 Answers2

0
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="qa-selenium">
    <test name="My Suite">
        <groups>
            <define name="functest">
                <include name="p1"/>
                <include name="p2" />
                <include name="module1"/>
                <include name="module2"/>
            </define>
            <define name="all">
                <include name="functest" />
            </define>
            <run>
                <include name="all"/>
            </run>
        </groups>
        <packages>
            <package name="your_package_name" />
        </packages>
    </test>
</suite>

You can try above in order to run test with all possible combination.

The above xml group gives me output in the following manner (Which takes the all possible combination).

enter image description here

Kavita Kulkarni
  • 193
  • 2
  • 4
  • 12
0

You can use first part of include name common and then use it in include name to execute all the tests as below

Test groups as below

@Test(groups = {"a-p1", "a-module1"})
public void p1module1() {
    System.out.println("p1module1");
}
@Test(groups = {"b-p2", "b-module1"})
public void p2module1() {
    System.out.println("p2module1");
}
@Test(groups = {"c-p1", "c-module2"})
public void p1module2() {
    System.out.println("p1module2");
}
@Test(groups = {"d-p2", "d-module2"})
public void p2module2() {
    System.out.println("p2module2");
}

Suite xml will look likes below

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="qa-selenium">
    <test name="My Suite">
        <groups>
            <run>
                <include name="a.*"/>
                <include name="b.*"/>
                <include name="c.*"/>
                <include name="d.*"/>
            </run>
        </groups>
        <packages>
            <package name="com.mycompany.qa.selenium.*"/>
        </packages>
    </test>
</suite>

In the above xml <include name="a.*"/> will execute the tests, which are having tagging with "a-p1", "a-module1"

No need to define separate include names for P1 and module, enter code heresame works for others, it will treated like AND not OR, Let me know if its correct answer of your question

Rakesh Burbure
  • 1,045
  • 12
  • 27