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 failed tests in testng
Most of the times, we have to run only the failed tests because due to shaky environment, some tests might fail. TestNG provides a feature that allows us to execute only failed tests. After the test suite is executed, TestNG creates one file in the output directory with name as testng-failed.xml. All you have to do is execute this file to run failed tests. If you are using Maven as your build management system, you will find that file under target/surefire-reports directory. Here is the sample XML file containing failed test configuration that was created by TestNG. Note that after executing this file, only failed tests will be executed.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite guice-stage="DEVELOPMENT" verbose="0" name="Failed suite [Suite]" parallel="classes">
<test name="Tests">
<classes>
<class name="org.softpost.Class1"/>
<class name="org.softpost.Class2"/>
</classes>
</test> <!-- Tests -->
<test name="Tests(failed)" parallel="classes">
<classes>
<class name="org.softpost.Class2">
<methods>
<include name="test1"/>
</methods>
</class> <!-- org.softpost.Class2 -->
<class name="org.softpost.Class1">
<methods>
<include name="test1"/>
</methods>
</class> <!-- org.softpost.Class1 -->
</classes>
</test> <!-- Tests(failed) -->
</suite> <!-- Failed suite [Suite] -->
Web development and Automation testing
solutions delivered!!