TestNG: Group Execution


import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;

public class DemoGroupsTestNG {
    @BeforeGroups({"Group2","Group1"})
    public void executeBeforeGroup(){
        System.out.println("execute Before Group ");
    }
    @AfterGroups("Group1")
    public void executeAfterGroup(){
        System.out.println("execute After Group1");
    }
 
    @Test(groups="Group1")
    public void method1(){
        System.out.println("method1");
    }
    @Test(groups="Group1")
    public void method2(){
        System.out.println("method2");
    }
    @Test(groups="Group2")
    public void method3(){
        System.out.println("method3");
    }
    @Test(groups="Group2")
    public void method4(){
        System.out.println("method4");
    }
    @Test(dependsOnGroups={"Group2","Group1"})
    public void method5(){
        System.out.println(" method5 test will execute");
    }
}




testng.xml-------------

<suite name="Suite" parallel="none">
  <test name="Test1">
    <classes>
      <class name="groupsTest.DemoGroupsTestNG "/>
    </classes>
  </test>
  <test name="Test2">
      <groups>
          <run>
          <include name="Group2"></include>
          </run>
      </groups>
    <classes>
      <class name="groupsTest.DemoGroupsTestNG "/>
    </classes>
  </test>
</suite>


Output
----------


executeBefore Group
method1
method2
executeAfter Group1
executeBefore Group
method3
method4
method5 test will execute
method3
method4

Copyright © 2017 qatoolsguide.blogspot.com || ALL RIGHTS RESERVED