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 TestNGRunning tests from main class in testng
Here is the source code example that shows how to execute the TestNG tests using main method. In below example, TestNG tests from org.softpost.Class1 and org.softpost.Class2 classes will be executed.
package org.softpost;
import org.testng.TestNG;
import org.testng.xml.XmlSuite;
public class MainClass {
public static void main(String[] args) {
TestNG testngRunner = new TestNG();
//To run tests in Parallel mode
testngRunner.setParallel(XmlSuite.ParallelMode.METHODS);
//Provide the list of test classes
testngRunner.setTestClasses(new Class[] {
org.softpost.Class1.class,org.softpost.Class2.class });
//Run tests
testngRunner.run();
}
}
Here is the output of above code.
[TestNG] Running:
Command line suite
Test2 from Class2
Test1 from Class2
Test2 from Class1
Test1 from Class1
===============================================
Command line suite
Total tests run: 4, Failures: 1, Skips: 0
===============================================
Web development and Automation testing
solutions delivered!!