BLOG

Img
Ranjan Singh Author's Perspective
img
5 Minutes read

TestNG in Automation Testing

TestNG is a unit testing framework which plays a major role in developing Test Automation frameworks using Java Programming language. Basically, TestNG is a user-friendly automation framework that overcomes the drawbacks and limitations of JUnit. Thus, introducing an entirely new set of features which makes it more powerful and useful. This automated testing framework helps in elimination of numerous limitations of the older framework. It facilitates the ability to write more flexible and powerful tests. It’s an open source framework and it can be used for any testing, API or UI testing.

Advantages of TestNG Unit Testing Framework

Below are the advantages of using TestNG Unit Testing Framework:

  • Test case creation is made easier
  • Groups the test cases
  • Prioritizes the test cases
  • Executes the test cases
  • Generates logs
  • Generates reports
  • Reads keywords/data from the excel files
  • Supports parameterization
  • Supports parallel execution of tests

Installing TestNG

To use TestNG Unit Testing Framework in Selenium Java Project, we must perform the below tasks:

  • Install TestNG extension in eclipse IDE
  • Configure TestNG jar files in the Selenium Java Project

TestNG Annotations

TestNG provides a huge set of annotations. The main reason behind TestNG’s popularity is nothing but the TestNG annotations, which can be used for configuring the test cases in selenium automation. Their annotations need to be used with Java methods, i.e., a line before the beginning of the Java methods. When a particular TestNG annotation is used before the Java method, the Java method will behave differently based on the specified annotation.

TestNG annotations begin with @ symbol. To use TestNG for executing the Selenium Automation code, the usage of the main() method in Java is no longer required. Using TestNG annotations, we can specify which methods need to be executed first and which methods can be executed later and so on.

Below are the different TestNG annotations which can be used in Selenium Automation:

  • @BeforeSuite: The annotated method will be run before all tests in this suite have run
  • @AfterSuite: The annotated method will be run after all tests in this suite have run
  • @BeforeTest: The annotated method will be run before any test method belonging to the classes inside the tag is run
  • @AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the tag have run
  • @BeforeGroups: The list of groups that this configuration method will run before. This method is guaranteed to run shortly before the first test method that belongs to any of these groups is invoked
  • @AfterGroups: The list of groups that this configuration method will run after. This method is guaranteed to run shortly after the last test method that belongs to any of these groups is invoked
  • @BeforeClass: The annotated method will be run before the first test method in the current class is invoked
  • @AfterClass: The annotated method will be run after all the test methods in the current class have been run
  • @BeforeMethod: The annotated method will be run before each test method
  • @AfterMethod: The annotated method will be run after each test method
  • @Test: The annotated method is a part of a test case
Ebook
Top 10 Sitecore 9 Form Features to Increase Lead Conversions

TestNG is a reliable Java-based testing framework capable of producing easy-to-understand HTML reports that can be generated automatically. It has certain advantages over JUnit like annotations, easily grouped test cases, capability to create parallel tests and many more. It makes automated tests more structured, readable, maintainable and user-friendly. It's high-end annotations like data-provider makes it easier to scale up as we can perform cross-browser testing across multiple devices, browsers, and their versions.

Ranjan Singh Lead Testing at Altudo


Talk to our Experts

Talk to us about how we bring together 1:1 personalisation, deep Martech Expertise, CX & Demand Gen Strategy, Engagement Analytics & Cross-Channel Orchestration to drive award winning experiences that convert

Get in touch for a complimentary consultation or a demo today.

Expert Workshops

Free workshops, expert advice & demos- to help your realize value with Sitecore

Register

Session Presentations

  • Sitecore + SFMC= Marketing Success
  • Transforming The Future Of eCommerce
Meet Us

Giveaways:

Participate in our event survey , meet us at our booth , get free giveaways & a chance to win an iPhone 11

Let’s go
Close Button