Sunday, 7 February 2016

Selenium:Groups in testNG

Groups in testNG:
===============
TestNG allows us to perform groupings of test methods.

Using TestNG can we can execute only set of groups while excluding another set. This gives us the maximum flexibility in divide tests and doesn't require us to recompile anything if you want to run two different sets of tests back to back.

Groups are specified in your testng.xml file using the <groups> tag. It can be found either under the <test> or <suite> tag. Groups specified in the <suite> tag apply to all the <test> tags.

//Sample example on testng groups
==========================
package testngdemo;

import org.testng.annotations.Test;

public class GroupDemo {

@Test(groups={"regression"})
public void testScript1() {
System.out.println("regression");

}

@Test(groups="regression")
public void testScript2() {
System.out.println("regression");

}
@Test(groups="regression")
public void testScript3() {
System.out.println("regression");

}
@Test(groups={"smoketesting"})
public void testScript4() {
System.out.println("smoketesting");

}
@Test(groups="smoketesting")
public void testScript5() {
System.out.println("smoketesting");

}
}


testng.xml:
=========
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="none">
  <test name="Test">
  <groups>
         <run>
            <include name="smoketesting"/>
            <exclude name="regression"></exclude>
         </run>
      </groups>
    <classes>
      <class name="testngdemo.GroupDemo"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->


No comments:

Post a Comment