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 TestNGExecuting JUnit tests in testng
TestNG allows you to execute JUnit tests from within TestNG framework. Below example demonstrates how to run JUnit tests. Note that we have used org.junit.Test annotation in below example.
package org.softpost;
import org.junit.Test;
public class JunitTests {
@Test
public void test1(){
System.out.println("Junit test");
}
}
Here is the TestNG XML file. Note that in test tag, we have used a special attribute called as junit and it’s value is set as true. TestNG executes JUnit tests using JunitCore.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Suite" parallel="false">
<test name="Tests" junit="true">
<classes>
<class name="org.softpost.JunitTests" />
</classes>
</test>
</suite>
Web development and Automation testing
solutions delivered!!