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


  1. This is really interesting, you’re a very skilled blogger.
    I have bookmarked this article page as I received good information from this.

    Best ERP Software Providers in Hyderabad | Best Sales Management Software in India

    Best ERP Software in India | Best Cloud ERP Software in Hyderabad

  2. I am glad that I saw this post. It is informative blog for us and we need this type of blog thanks for share this blog, Keep posting such instructional blogs and I am looking forward for your future posts. Python Projects for Students Data analytics is the study of dissecting crude data so as to make decisions about that data. Data analytics advances and procedures are generally utilized in business ventures to empower associations to settle on progressively Python Training in Chennai educated business choices. In the present worldwide commercial center, it isn't sufficient to assemble data and do the math; you should realize how to apply that data to genuine situations such that will affect conduct. In the program you will initially gain proficiency with the specialized skills, including R and Python dialects most usually utilized in data analytics programming and usage; Python Training in Chennai at that point center around the commonsense application, in view of genuine business issues in a scope of industry segments, for example, wellbeing, promoting and account. Project Center in Chennai


Selenium4: Working with two parallel windows in Selenium Automation

A new method newWindow() is introduced in Selenium 4 (Alpha). Using this method we can open a new tab or new window from the current window...