Creating testng.xml file with multiple tests
In our previous blog, we have created a testng.xml file with only one test in a suite. But, TestNG allows to define multiple tests in a single suite. This way we can segregate our tests and can create different tests based on our requirement (i.e. smoke tests, sanity tests and integration tests etc…).
Now we’ll see creating multiple tests in testng.xml file:
1.Open eclipse and create a project with multiple test classes (i.e. multiple Java files)
2.Create a testng.xml file.
Can see the screenshot below for the same.
3.Now will update the testng.xml file with multiple tests in a single suite.
Below is the screenshot for the same:
The testng.xml file defines a suite with the name Suite. The suite contains two tests with names FirstTest and SecondTest respectively. These tests are configured to execute separate classes “com.test.testngframework.FirstTest” and “com.test.testngframework.SecondTest”.
When the testng.xml file is executed as a suite in TestNG, each class is executed by a separate test section of a suite.
4.Now run the testng.xml file and see the generated output.
Below is the screenshot for the same:
This way we can include multiples tests according to our requirement and execute the same. Once the output is generated, we can able to see the results as separate tests to understand and analyse the report.