What is a TestNG xml file in TestNG?

Rest AssuredTestNGDynamic Programming

The testng.xml file has the numerous uses as listed below −

  • Test cases are executed in groups.

  • Test methods can be included or excluded in the execution.

  • The execution of multiple test cases from multiple java class files can be triggered.

  • Comprises names of the folder, class, method.

  • Capable of triggering parallel execution.

  • Test methods belonging to groups can be included or excluded in the execution.

Example

Code implementation of TestNG.xml file

<?xml version = "1.0" encoding = "UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name = "Cycle1">
   <test name = "Tutorialspoint">
      <classes>
         <class name = "Test1" />
         <methods>
            <exclude name= “Login.*”/>
         </methods>
      </classes>
   </test>
</suite>

Here as per the xml file, all the test methods with starting name Login will be excluded from test execution.

@Test
public void VerifyPay(){
   System.out.println("Verify payment is successful”);
}
@Test
public void LoginAdmin(){
   System.out.println("Login is successful in admin”);
}
@Test
public void LoginSystem(){
   System.out.println("Login is successful”);
}

Here as per the java class file, only VerifyPay() will be executed since all methods starting with the name Login will be excluded from test execution.

raja
Updated on 19-Nov-2021 12:30:16

Advertisements