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 tests in testng
We can execute tests using XML suite file as shown in below example.Syntax of Suite file
- suite tag contains one or more test tag. Each test tag can contains one or more tests to be executed.
- A test tag can contain tags like classes, groups etc. We can also pass the attribute preserver-order which is used to specify if the tests should be executed in given order.
- In test tag, preserve-order attribute is used to run the tests in the order as given in XML file
- In test tag, group-by-instances attribute is used to group tests by test class instances
Running tests from specific classes
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Softpost Suite">
<test name="softpostTests" preserve-order="true" >
<classes>
<class name="org.softpost.AppTest">
<methods>
<include name="test1"/>
<exclude name="test2"/>
</methods>
</class>
<class name="org.softpost.TimeoutTests" />
</classes>
</test>
</suite>
Running Tests from package
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Softpost Suite">
<test name="softpostTests" preserve-order="true" >
<packages>
<package name="org.softpost"/>
</packages>
</test>
</suite>
Running tests from Specific Groups
Notice that when running the tests from a group, you need to also specify the packages or classes containing tests from those group.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Softpost Suite">
<test name="softpostTests" preserve-order="true" >
<groups>
<define name="desktop_browsers">
<include name="chrome"/>
<include name="ie"/>
</define>
<define name="mobile_browsers">
<include name="android"/>
<include name="ios"/>
</define>
<run>
<include name="desktop_browsers"/>
<exclude name="mobile_browsers"/>
</run>
</groups>
<packages>
<package name="org.softpost"/>
</packages>
</test>
</suite>
This is how we can execute tests using suite file in TestNGWeb development and Automation testing
solutions delivered!!