How to create TestNG suite file.

TestNG suite means grouping two or more than two classes to execute with a single command.

How to create:
Create some test class as I created below two test class  “FirstTest.java” and “SecondTest.java” java files.

FirstTest.java:

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class FirstTest {
       
        @BeforeClass
        public void beforeClass() {           
           System.out.println("One time executed before first mathod");
        }
         
        @AfterClass
        public void afterClass() {
            System.out.println("One time executed after last method");
        }
                  
        @Test
        public void testFirstMethod() {       
           System.out.println("@Test - executed first test method");
        }
}



SecondTest.java

import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class SecondTest {     
           
        @BeforeClass
        public void beforeClass() {   
                System.out.println("one time executed before first mathod");
        }
         
        @AfterClass
        public void afterClass() {    
                System.out.println("one time executed after last method");
         }     
         
        @Test
        public void testSecondMethod() {       
           System.out.println("@Test - executed second test method");
        }
}


Suite.xml file is suite file of above classes:

 
<!DOCTYPE suite SYSTEM "http://beust.com/testng/testng-1.0.dtd" >
<suite name="TestNG Suite">
  <test name="method">
    <classes>
       <class name="com.test.FirstTest" />
       <class name="com.test.SecondTest" />
    </classes>
  </test>
</suite>

Run this suite file using TestNG, both test classes should be executed.

4 comments:

  1. how to run the suite.xml file in eclipse

    ReplyDelete
    Replies
    1. Just Right click on Suite.xml file on eclipse, you get TestNG option.

      Delete
  2. WOW just what I was searching for. Came here by searching for cellulite cream

    Here is my web blog :: co zrobi䟺 cellulitem

    ReplyDelete
  3. can u please tell me , that how to use loop for tesing web application ?
    i have to create new user so every time i have to add values manually in selenium..so how can i use loop for that?

    ReplyDelete

Leave your comments, queries, suggestion I will try to provide solution