This post was most recently updated on June 25th, 2019
TestNG: Powerful and easy to use framework/tool over JUnit and NUnit. Extensively used by all automation testers due to its reporting feature.
What are the features of TestNG?
- Annotations are widely used in the TestNG framework. Annotation is used to describe a piece of code that is inserted into the program or business logic used to control the flow of methods in the java. Testers need to understand the working and uses of each annotation while they are working on TestNG.
- Support for parameters: Users can pass parameter values through an XML configuration file to the test methods, which can then be used inside the tests method.
- Supports multi-threaded execution allows the execution of test cases in a multi-threaded environment. It can be used for parallel test execution to save execution time or to test multiple test scenarios.
- Dependent methods: This is one of the major features of TestNG where you can run a dependent test method. You can also decide the execution of the test methods.
- Groups: You can create groups to run particular test cases groups this will be useful when you need to do “Smoke” or “Regression” testing. Then you can create a group and run the particular test group.
- Support for data-driven testing (with @DataProvider). When data-driven tests are required, with the help of a data provider, the same can be achieved.
- Data-driven testing: same test method can be executed multiple times based on the data.
- Reporting: TestNG generates an XML and HTML report by default for its test execution. You can also add custom reports to the framework if required.
- API: TestNG provides an easy extension of API, this helps in adding custom extensions or plugins to the framework depending upon the user requirement.
Advantages of TestNG
- In TestNG Annotations are easy to use and understand as their names explain about them like @BeforeTest, @AfterTest, @BeforeClass, @AfterClass, etc.
- In TestNG, we don’t need to extend the class which saves from developing duplicate code.
- TestNG allows us to define the dependent test cases each test case is independent to other test cases, Example it uses dependsOnMethods attribute @Test(dependsOnMethod).
- TestNG allows you to group the test cases easily specific test cases can be run which helps in the fast execution and saves time.
Example, Let’s consider a scenario where we have created two groups such as ‘Smoke’ and ‘Regression’. If you want to execute the test cases in a ‘Regression’ group, then this can only be possible in the TestNG framework. - Parallel execution of test cases is possible in TestNG.
How to run testng xml in azure devops