0% found this document useful (0 votes)
5 views2 pages

TESTNG Groups

Grouping in TestNG allows for the categorization of test methods based on various criteria, enabling selective execution of tests rather than running all of them. Groups can be defined at both the <test> and <suite> levels, with the scope of groups varying accordingly, and can be included or excluded in the testng.xml configuration file. Different types of groups such as Test Groups, Exclude Groups, Meta Groups, and Partial Groups provide flexibility in managing and executing tests efficiently.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

TESTNG Groups

Grouping in TestNG allows for the categorization of test methods based on various criteria, enabling selective execution of tests rather than running all of them. Groups can be defined at both the <test> and <suite> levels, with the scope of groups varying accordingly, and can be included or excluded in the testng.xml configuration file. Different types of groups such as Test Groups, Exclude Groups, Meta Groups, and Partial Groups provide flexibility in managing and executing tests efficiently.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

How to Group test in TestNG

1. What is grouping ? why we need grouping


grouping is nothing but catogarization of test methods (may be based on Test
phase).
Generally dont execute all the test but run few selected one.

e.g of group can be as follows:


smoke => high level scenarios ensure build is good say 10 testcases
functional => 90 testcases
regression => 95 testcases
daily build =>40 testcases
weeklybuild => 100 testcases
windows/ios OSbasedCatogarization - 50 testcases

one way is to create multiple xml file... e.g smoketest.xml,


functionalTests.xml....but this is not good way
TestNG provide better way using group concept

we can do this grouping either at <test> or <suite> level


when we define groups in <test> tag ...scope of those group is limited to that
test only and not applicable to other test in that suite
when we define groups in <suite> but outside <test> tag ...scope of those group
is applicable to all tests in that <suite>
when we define greoup in <suite> as well as inside <test> tag ... group defined
at suite level is executed in each test in addition to group defined at test level

2. How to define grouping


we have to pass array of group names to groups attribute in @Test annonation
above current methods /class
and we have to call it in testng.xml using

Types of groups and how to use them in xml


- Test Groups : use <include name="groupname1"/> <===to include test
from this groupname1
- Exclude GRoup : use <exclude name="groupname2"/> <===to exclude test
from groupname2
- Meta Group : use <include name="metagroupname"/> <===is group of
groups
- Partial Group : when we add @Test(groups={"groupname"}) above the
class ....then all Test method of that class become part of that group

Here it will execute test which are part of groupname1 excluding the tests which
are also part of groupname2
<groups>

<run>
<include name="groupname1"/> <===to include test from this groupname1
<exclude name="groupname2"/> <===to exclude test from groupname2
</run>

</groups>

We can also define group of groups in xml inside <group> tag and use it in run
to run group of tests

<groups>
<define name="dailybuild"> <====Metagroup
<include name="smoke"/>
<include name="sanity"/>
</define>

<define name="weeklybuild">
<include name="smoke"/>
<include name="sanity"/>
<include name="functional"/>
<include name="regression"/>
</define>

<run>
<include name="dailybuild"/>
</run>
</groups>

You might also like