TestNg Groups

Grouping is very good feature of testng. Its a next generation testing techniques. In previous blog we learn what is TestNg, how to execute Testng program etc. Now we explain how to make groups in testng.

Benefits of grouping: Suppose we have 100 test methods in a single test class and we defined some high priority test methods and some low priority test methods.From these method we want to run only high priority test methods. So we can easily make the groups for it.

We will create test case and we will defined some methods where we can defined high, low priority.

Here is the code:

import org.testng.annotations.Test;

public class TestGroup1 {

@Test(priority=0,groups = {"high"})
public void login()
{
System.out.println("Do login");
}

@Test(priority=1, groups = {"low"})
public void fillform()
{
System.out.println("fill the form");
}

@Test(priority=2, groups = {"high"})
public void searchdata()
{
System.out.println("serach the data");
}

@Test(priority=3, groups = {"medium"})
public void enddata()

{
System.out.println("end data");

}
}
 

For grouping we have to define groups in testing.xml.Here we run the only high priority test methods.

<test name="Testing group1" >
<classes>
<class name="TestGroup1"/>
</classes>
</test>

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

In testing xml we defined <groups> and <run> tag. <groups> tag defines the group and </run> tag represents the group that needs to be run.

 

testng result

We can easily see the html report which is generated by testng.

testng report

login and search data are the high priority groups so when define high priority groups in testng.xml it run the only high priority groups test methods.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s