Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"




Test Suite in TestNG:-

The test suite is used to execute more than one test class using a single XML file.

Test Suite always will be defined by an XML file that contains multiple test classes using XML tag.


First Create two different Test Case Classes 

package scs;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;

public class Test1 {

@BeforeClass
public void bclass(){
System.out.println("Before Class1");
}

@AfterClass
public void aclass(){
System.out.println("After Class1");
}
@BeforeSuite
public void bsclass(){
System.out.println("Before SUIT1");
}

@AfterSuite
public void asclass(){
System.out.println("After Suit1");
}
  @Test
  public void f() {
  System.out.println("Test Class1");
  }
  @BeforeTest
  public void beforeTest() {
  System.out.println("Before Test");
  }

  @AfterTest
  public void afterTest() {
  System.out.println("After Test");
  }

}


Create another class Test2

package scs;

import org.testng.annotations.Test;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;

public class Test2 {
  @Test
  public void f() {
  System.out.println("Test Class2");
  }
  @BeforeTest
  public void beforeTest() {
  System.out.println("Before Test CLASS2");
  }

  @AfterTest
  public void afterTest() {
  System.out.println("After Test Class2");
  }

}
        

Syntax of testsuite.xml

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name = "Suite1">

   <test name = "exampletest1">
      <classes>
         <class name = "Test1" />
      </classes>
   </test>
  
   <test name = "exampletest2">
      <classes>
         <class name = "Test2" />
      </classes>
   </test>


@BeforeSuite and @AfterSuite Annotation can be defined in the source code of class which will be executed before suite execution and after suite execution for a particular class.



Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post