TestNG - Overview


Testing is the process of checking the functionality of the application whether it is working as per requirements and to ensure that at developer level, unit testing comes into picture. Unit testing is the testing of single entity (class or method). Unit testing is very essential to every software company to give a quality product to their customers.

JUnit has driven developers to understand the usefulness of tests, especially of unit tests when compared to any other testing framework. Leveraging a rather simple, pragmatic, and strict architecture, JUnit has been able to "infect" great number of developers. Features of JUnit can be seen in Junit Features.

Some of the short comings of JUnit are:

  • Initially designed to enable unit testing only, now used for all kinds of testing.

  • Cannot do dependency testing.

  • Poor configuration control (setUp/tearDown).

  • Intrusive (forces you to extend classes and name your methods a certain way).

  • Static programming model (forces you to recompile unnecessarily).

  • The management of different suites of tests in complex projects can be very tricky..

What is TestNG?

Definition of TestNG as per its documentation is:

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use.

TestNG is an open source automated testing framework; where NG of TestNG means Next Generation. TestNG is similar to JUnit (especially JUnit 4), but its not a JUnit extension. Its inspired by JUnit. It is designed to be better than JUnit, especially when testing integrated classes. The creator of TestNG is Cedric Beust.

TestNG eliminates most of the limitations of the older framework and gives the developer the ability to write more flexible and powerful tests. As it heavily borrows from Java Annotations (introduced with JDK 5.0) to define tests, it can also show you how to use this new feature of the Java language in a real production environment.

TestNG Features

  • Annotations.

  • TestNG uses more Java and OO features.

  • Supports testing integrated classes (e.g., by default, no need to create a new test class instance for every test method).

  • Separate compile-time test code from run-time configuration/data info.

  • Flexible runtime configuration.

  • Introduces ‘test groups’. Once you have compiled your tests, you can just ask TestNG to run all the "front-end" tests, or "fast", "slow", "database", etc...

  • Supports Dependent test methods, parallel testing, load testing, partial failure.

  • Flexible plug-in API.

  • Support for multi threaded testing.