Monday, November 13, 2017

How to apply Grouping to test cases in TestNG?

Grouping in TestNG is very simple, it is used to execute specific set of test cases at a time. This grouping can be done based on the test cases functionality or module that they belong or the test set they present (smoke or regression) it is completely depends on tester requirement.

A test method can be categorized into one or more groups, groups is the attribute used in the @Test annotation.

@Test(groups ={'Sales'}) // test method belongs to 'Sales' group
@Test(groups = {'Sales','Marketing'}) //test method belongs to 'Sales and Marketing' groups

Let us understand grouping with an example, assume we are automating an e-commerce application and there are two modules say Sales and Marketing. And regression test cases of these two modules are scripted into two sets (java classes) say regressionSet1 and regressionSet2. That is each set contains test cases from both the modules. Some tests are marked as Sales, and some are marked as Marketing and some are marked for both modules.

Check the below screenshot, two sets of test cases that are grouped under Sales and Marketing.

Now create the testng.xml file to execute only sales module test cases. We need to add the <group></group> tag inside<test></test> and we have to include the groups to be executed inside the <group></group> as below.

Run the testng.xml as TestNG suite and checkout the results.

All the tests that are marked as Sales, Sales and Marketing were executed and Marketing group tests were ignored. Similarly if we can execute Marketing test cases also.

Please comment your queries and suggestions on this topic. Thanks for reading!!
#seleniumbabu #HappyLearning

No comments:

Post a Comment

DevOps 01: What is DevOps and How it benefits organizations?

DevOps is a culture in an organization, where the development team and operations team help each other by sharing information, process and t...