TestNG Introduction

10 April, 2012
Testing is crucial part of Software development life cycle. There are many types of Testing like unit, functional, integration, system, automation and so forth. TestNG can be integrated into all phases of testing. TestNG is one of the widely used test automation frameworks in Java.

TestNG overcomes the limitations of the another popular testing framework named JUnit. 'NG' stands for "Next Generation". Most Selenium users use TestNG more than JUnit because of the many advantages it provides. TestNG offers lot of features. However we do not use all these features for Selenium Test Automation. In the coming chapters, we will discuss the features which we use in Selenium. TestNG makes Selenium tests easier to understand. Also, WebDriver has no native mechanism to generate test reports. TestNG can generate graphical test reports that are easy to understand.

TestNG was developed by Cedric Beust to overcome the deficiencies of Junit. Few of the features that TestNG has over Junit are:
  • More Annotations
  • Test cases can be grouped more easily
  • Dependency test
  • Grouping of test methods
  • Multithreaded execution
  • In-built reporting framework

TestNG is written in Java and can be used with Java. In TestNG, suites and tests are configured through XML files.

Following are the few most important features of TestNG used in Selenium:

  • Multiple Before and After annotations: These annotations are used for different setup and cleanup options.
  • XML-based test configuration and test suite definition: Test suites are configured mainly using XML files. An XML file is used to create test suites using packages, classes, test methods, and TestNG groups. We can also pass parameters to test methods or classes.
  • Dependent methods: We can make TestNG execute a dependent test method to run after a given test method.
  • Groups: We can assign certain test methods into particular named groups and make TestNG to include/exclude a particular group in a test.
  • Dependent groups: Like dependent methods, this feature allows test methods belonging to one group being dependent upon another group.
  • Parameterization of test methods: We can pass parameter values through XML file to the test methods.
  • Data-driven testing: We can use this feature for data-driven testing of test methods. The same test method will be executed 'n' number of times based on the data.
  • Multithreaded execution: Test cases can be run in a multithreaded environment. This helps in running the tests in a parallel fashion to reduce the execution time.
  • Graphical Reporting: TestNG generates the reports in HTML report after the test execution. We can style the reports to make it more graphical and easier to understand.

Downloading TestNG

As TestNG is used for Java programs, Java JDK should be installed and set up on your machine. TestNG can be downloaded and installed, and run in many ways as below:
  • Using command line
  • As an IDE (like Eclipse, IntelliJ) plugin
  • Using ANT, Maven
In case you just want to download the TestNG JAR, you can from URL: http://testng.org/testng-6.8.zip

Eclipse users can install TestNG from: Help -> Install New Software. Select install from "http://beust.com/eclipse"


That concludes the introduction to TestNG. We shall discuss all the features of TestNG used in Selenium tests in detail in the coming topics. If you have any queries or need any assitance, please leave a comment. Until next time, happy learning!

No comments:

Post a Comment