TestNG Tutorial
Introduction to TestNG Configuration and set up of TestNG project Simple TestNG project in IntelliJ IDEA TestNG annotations Assertions in TestNG Difference between assertEquals and assertSame Ignoring the tests in TestNG Grouping the tests timeOut tests in TestNG Exception tests in TestNG dependsOnMethods dependsOnGroups Hard and Soft dependencies Passing parameters using XML file Passing parameters using Data providers Dynamic Data Providers group-by-instances attribute in TestNG XML suite file Test priorities in TestNG invocationCount in TestNG Executing Selenium tests using TestNG Executing TestNG tests using main method Executing JUnit tests from within TestNG Running tests in Parallel in TestNG Executing only failed tests in TestNG TestNG integration with Maven TestNG integration with Gradle Reporter class in TestNG TestNG Reports Execution Listener Test Listener Comparison between JUnit and TestNGdepends on group in testng
In TestNG tests, we can have a test depending on another group of tests. Let us say we have 3 tests – testGroup, sanityTest1 and sanityTest2. Before executing the testGroup test, we want that all tests from sanity group should be executed. Then we can use dependsOnGroups parameter as shown in below example. Please note that all test methods should be in same test Class.
package org.softpost;
import org.testng.annotations.Test;
public class TestDependsOnGroups {
@Test(groups = { "sanity" })
public void sanityTest1() {
System.out.println("Inside Sanity1");
}
@Test(groups = { "sanity" })
public void sanityTest2() {
System.out.println("Inside Sanity2");
}
@Test(dependsOnGroups = { "sanity" })
public void testGroup() {
System.out.println("Inside testGroup()");
}
}
Here is the output of above example.
[TestNG] Running:
C:UsersSagar.IdeaIC15system emp-testng-customsuite.xml
Inside Sanity1
Inside Sanity2
Inside testGroup()
===============================================
Default Suite
Total tests run: 3, Failures: 0, Skips: 0
===============================================
Web development and Automation testing
solutions delivered!!