Inspired by NUnit and JUnit, TestNG is a type of java testing open-source framework in selenium. It provides more powerful features than JUnit and is easy to use. NG stands for next-generation which means new features and functionalities that TestNG brings with it. TestNG supports all ranges of testing such as simple unit testing or be it complex integration testing. It helps to simplify all testing requirements such as functional testing, regression, or end-to-end testing. It is widely used by testing companies and is stimulated by JUnit Java and NUnit .Net platforms.
Below Is How We Can Create a TestNG.XML File
To create or maintain multiple test cases we require a TestNG.XML file. The main prerequisites are that we need to configure our test run, set the test dependency, include/exclude any test, set priority, and create a class or package in the file.
- Right-click on the project folder → go to New and then select ‘File’.
- In the New file wizard, add the filename as ‘testing XML’ and click on the Finish button.
- After this, it will add an XML file below the project folder.
- Write the below code:
The suite is signified by one XML file. It can comprise one or more tests.
A Test can hold one or more TestNG classes.
A Class is defined as a Java class that comprises TestNG annotations.
It can contain more than one test method.
Classes tag is named as -> a combination of the Package name and the Test Case name.
A Test method is a Java method annotated as @Test in the source file.
**User can choose any name for Test Suite & Test Name**
Example of TestNG.XML File
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<parameter name="Username" value="email@example.com"/>
<parameter name="password" value="test@123"/>
<parameter name="mobile_number" value="1234567899"/>
</test><!-- Test -->
</suite><!-- Test -->
TestNG framework is widely used by many software companies that use selenium because of its multiple ranges of advantages and features. This is very comfortable and easy to use. Test cases can be easily created using annotations in TestNG. It supports data-driven testing. It supports parameterization as well. We can create a group of test cases, and execute them based on priority. It supports parallel execution and generates logs that are of real help. No need for inheritance property. It allows us to define dependent test cases. Any name can be given to methods without any constraint of naming.
Post a Comment