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 TestNGMaven integration in testng
Maven has a very good support for TestNG framework. Maven commands to execute TestNG tests- To run all testNG tests, you can use – mvn test
- To execute tests from specific groups, you can use – mvn test -Dgroups=”sanity,smoke”
- To execute tests apart from specific groups, you can use – test -Dgroups=!”reg”
- To execute tests from specific test class, you can use – test -Dtest=BankTest
- To execute specific test method from specific test class, you can use – test -Dtest=BankTest#test2
- We can use suiteXmlFile tag to specify the xml file containing tests to be run.
- We can use groups tag to specify the names of groups that we want to run.
- excludedGroups tag can be used to skip tests belonging to specific groups.
- We can use parallel tag to specify the type of parallelism. Possible values are methods, classes etc.
- We can use excludes tag to exclude specific test classes from running.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Component Tests" verbose="2" annotations="JDK">
<test name="a-t1" preserve-order="true" >
<classes>
<class name="org.softpost.AppTest" />
</classes>
</test>
</suite>
Here is the sample surefire plugin block.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile>
</suiteXmlFiles>
<excludedGroups>reg</excludedGroups>
<groups>sanity,abc</groups>
<parallel>methods</parallel>
<threadCount>10</threadCount>
<excludes>
<exclude>org.softpost.AppTest</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
Web development and Automation testing
solutions delivered!!