TestNg
Course Index
Index

TestNG advanced

Run testng.xml programmatically

Java
Copy
import org.testng.TestNG;
import java.util.Arrays;

public class RunTestNGXML {
    public static void main(String[] args) {
        TestNG testng = new TestNG();
        
        // Provide the path of testng.xml file
        testng.setTestSuites(Arrays.asList("testng.xml"));
        
        // Run TestNG
        testng.run();
    }
}

Group of Groups

XML
Copy
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="MySuite">
    
    <!-- Define a new group combining "sanity" and "regression" -->
    <groups>
        <define name="critical">
            <include name="sanity"/>
            <include name="regression"/>
        </define>
    </groups>

    <test name="Group of Groups Test">
        <groups>
            <run>
                <include name="critical"/>  <!-- Runs all tests in "sanity" and "regression" -->
            </run>
        </groups>
        <classes>
            <class name="SampleTest"/>
        </classes>
    </test>

</suite>