Executing testng.xml
Table of contents
Let us dive into the Execution of the TestNG via Maven.
Maven supports TestNG out of the box without any need of downloading any additional plugins.
Add Maven Surefire Plugin under the
<plugins>
Need to Specify TestNg dependency in pom.xml
Add Suite XML File under
<configuration>
mentioning the correct testng.xml file name under<suiteXmlFile>
Execute via = mvn test
On Completion of tests, TestNG creates a default Report; Creating a new folder with the Suite name mentioned in the .xml file.
- NOTE: The hierarchy of the XML file is - first
<suite> tag
, next<test> tag
and then lastly<classes> tag
. As stated we can name anything to the Suite and Tests but, the class name has to be perfect with the .java.
Handling multiple tests in one TestNG file :
- As
<suite>
is the top-most in the hierarchy, this is where we've to place our test classes.
Example: testng-multiple-tests.xml, used Second Test Case Login. Also, ensure the same testng file name is used in POM under<suiteXmlFile>