TESTNG FEATURE-GROUPING OF TESTCASES
Grouping is an important Feature of TestNG. This helps us to partition the tests and doesn’t require you to recompile anything if you want to run two different sets of tests back to back.
Groups are specified in your testng.xml file and can be found either under the
Groups specified in the
Note that groups are accumulative in these tags: if you specify group “a” in
For example, it is quite common to have at least two categories of tests
Check-in tests: These tests should be run before you submit new code. They should typically be fast and just make sure no basic functionality was broken.
Functional tests : These tests should cover all the functionalities of your software and be run at least once a day, although ideally you would want to run them continuously.
Its evident that when ever the build provided to the QA team, for quick round of testing to
confirm the build is working fine by running “sanity” group of testcases.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
public class Grouping{ //groups is an attribute for @Test Annotation. //groups is an array of values @Test(groups={"sanity","regression"}) public void Login() { } @Test(groups={"regression"}) public void VerifyLinkText() { } @Test(groups={"sanity","regression"}) public void Logout() { } } |
XML File:
1 2 3 4 5 6 7 8 9 10 11 12 |
<test name="Test1"> <groups> <run> <include name="sanity"/> </run> </groups> <classes> <class name="packagename.classname"/> </classes> </test> |
Refer to the link for information->http://testng.org/doc/documentation-main.html
Inclusion & Exclusion of Groups:
In TESTNG we can even mark a Single @Test that belongs to more then one group as well. Mark tests as sanity,regression and classify the tests based on critical,high,medium and low as shown below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
package com.totalqa.testng; import org.testng.annotations.Test; public class GroupingEx { @Test(groups={"sanity","critical"}) public void m1() { } @Test(groups={"sanity","regression","medium"}) public void m2() { } @Test(groups={"regression","critical"}) public void m3() { } @Test(groups={"sanity","regression","critical"}) public void m4() { } } |
Refer to the testng xml file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suite" verbose="5"> <test name="Test"> <groups> <run> <include name="sanity" /> <include name="medium" /> <exclude name="critical" /> </run> </groups> <classes> <class name="com.totalqa.testng.GroupingEx"/> </classes> </test> <!-- Test --> </suite> <!-- Suite --> |
Output:
1 2 3 4 5 6 |
PASSED: m2 =============================================== Test Tests run: 1, Failures: 0, Skips: 0 =============================================== |