What’s this TestNG?

Numanhan Duran
3 min readOct 27, 2022

Hello to everyone. 🫡

While developing test automation projects with Selenium, I was defining “TestNG” dependency in the pom.xml file. But I did not ask questions such as why am I using TestNG, why do I need it, what is it good for. I just used it. In this article, I will talk about TestNG a little.

What is TestNG?

Developed by Cedric Beust, this framework aims to eliminate the weaknesses of JUnit and NUnit. TestNG(Next Generation) aims to provide flexibility and ease of use beyond eliminating JUnit and NUnit weaknesses.

Using TestNG, we can generate a test report and see how many successful and how many failed test scenarios we have at the end of the test. It also allows us to run failed test scenarios separately. We can give an example of this;

  • Let’s add our favorite Gucci wallet from an online store to the cart and test the process until the purchase is complete. (I actually want to buy a Gucci wallet 😂)
  • Let’s assume that we have 5 different scenarios for this case. Let’s assume that we get an error in the 3rd scenario after these scenarios start running.
  • Here, TestNG continues to run the test from this scenario after the corrections are completed in the place where the error is received. So we don’t have to run all scenarios from the beginning.

TestNG generates an xml file named testng-failed where it keeps the failed tests. When we want to run only failed tests, in fact only the xml file created by TestNG runs.

TestNG Advantages

  • Notations
  • Annotations
  • Running tests on related Threads
  • Multi thread test support
  • Data Driven Test, thanks to @DataProvider notation
  • Flexible test configuration
  • BeanShell support for flexibility
  • Self-logging support
  • Object-oriented development
  • It includes features such as dependency testing support.

Selenium with TestNG

Selenium tests do not create a suitable format for test results, so we can generate test results using TestNG.

  • In the report created as a result of the run test scenarios, the number of test scenarios, the number of failed test scenarios and the number of skipped test scenarios are reported accordingly.
  • Multiple test cases are grouped in the testng.xml file. You can set which test case to give priority to.
  • The same test case can be executed multiple times using the keyword ‘invocation count’.
  • Using TestNG, you can run multiple test cases in multiple browsers i.e. cross browser testing.

Sample Code Comparison

  • Example Code without TestNG
  • TestNG using Example
  • In the example code here, the test run is not stopped when an error is encountered in the code block under @Test. Errors are indicated as steps in the report

I wanted to briefly share with you the situations that I understood from TestNG. I hope it was a useful writing. By the way, since Selenium provides external access to the web project, be careful not to confuse unit test and other test cases in test concepts.

If anyone has read the article to the end, I am currently looking for a job as a QA Engineer. I will be happy if you can help :)

Happy Testing..:)

--

--