Professional Documents
Culture Documents
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.X</version>
</dependency>
TestNG tests are often configured using an XML file. Create a file named testng.xml to define test
suites, test classes, and other configurations
<suite name="MyTestSuite">
<test name="MyTestClass">
<classes>
<class name="com.example.MyTestClass"/>
</classes>
</test>
</suite>
🌟 Test Annotations:
🌟 Test Methods:
Write test methods and annotate them with @Test. Define assertions using TestNG assertion
methods (e.g., assertEquals, assertTrue).
🌟 Test Suites:
Group tests into suites using the testng.xml file. Define dependencies between test methods or
groups.
🌟 Parameterized Tests:
@Test
@Parameters({"param1", "param2"})
public void testWithParameters(int param1, String param2) {
// Test logic using parameters
}
🌟 DataProvider:
@DataProvider(name = "testData")
public Object[][] provideTestData() {
return new Object[][]{
{1, "apple"},
{2, "banana"},
{3, "cherry"}
};
}
@Test(dataProvider = "testData")
public void testWithData(int id, String name)..
@Test(groups = "smoke")
..
@Test(groups = "regression", dependsOnGroups = "smoke")
..
🌟 Listeners:
Implement TestNG listeners for custom actions before/after test methods, classes, suites, etc.
🌟 Parallel Execution:
TestNG supports parallel execution. Set parallel mode and thread count in the testng.xml file.