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 TestNGTest Priorities in testng
We can assign priority to each test in TestNG. Tests with higher priorities are executed first. Below example demonstrates how to use test priorities. We have 3 tests in below test class. Test with priority 1 is executed before test with priority 2. Then test with priority 2 is executed. Finally test 3 is executed. Notice that tests will always execute in that order.
package org.softpost;
import org.testng.annotations.Test;
public class TestPriorities {
@Test( priority = 1 )
public void test1() {
System.out.println("test1");
}
@Test( priority = 3 )
public void test3() {
System.out.println("test3");
}
@Test( priority = 2 )
public void test2() {
System.out.println("test2");
}
}
Here is the output of above example.
[TestNG] Running:
C:UsersSagar.IdeaIC15system emp-testng-customsuite.xml
test1
test2
test3
===============================================
Default Suite
Total tests run: 3, Failures: 0, Skips: 0
===============================================
Web development and Automation testing
solutions delivered!!