top of page

Welcome
to NumpyNinja Blogs

NumpyNinja: Blogs. Demystifying Tech,

One Blog at a Time.
Millions of views. 

A Beginner's Guide to TestNG Automation Framework with Sample Project structure

If you are starting your journey in test automation with Selenium, you will quickly come across a powerful testing framework called TestNG. TestNG is widely used in automation projects because it provides better test management, flexibility, and reporting compared to traditional frameworks.


In this blog, you will understand what is TestNG, why it is used and the basic concepts beginners need to know to get started.


What is TestNG?

TestNG stands for "Test Next Generation". It is a testing framework inspired by JUnit and NUnit but designed with additional powerful features that make automation testing easier and more efficient.

TestNG is commonly used with Selenium WebDriver to build automation framework for testing Web applications.

It provides powerful features such as annotations, grouping of tests, parallel execution and automatic report generation, because of these features, it helps us to create clean, flexible and maintainable automation test scripts.


Why Do We Use TestNG?

Before frameworks like TestNG, automation testing had several limitations such as poor test organization and limited reporting.

TestNG is a powerful testing framework that make automation testing more structured by providing several useful features such as:

  1. Test Annotations

    TestNG allows us to organize test cases using annotations. Annotations helps us to control the execution flow of test methods in automation. They define when a particular methos should run, such as before tests start, after tests finish or before each text case.

  2. Grouping of Tests

    Tests are organized into local groups and you can choose which groups to run

  3. Parallel Execution

    Tests run simultaneously across multiple threads, processes, or machines.

  4. Data-Driven Testing

    TestNG supports data providers, which allows the same tests to run with multiple sets of test data

  5. Dependency Methods

    TestNG allows defining dependencies between test methods. A test can be configured to run only after another test passes. Example. if the main test passes dependent tests run, if the main test fails dependent test is skipped.

  6. Build In reporting

    TestNG automatically generates detailed execution reports showing passed, failed, skipped tests. common reports files are index.html which provides detailed report of all test cases and emailable-report.html for the overall summary report of the execution.

  7. Retry Mechanism

    TestNG supports retrying failed test cases due to temporary network issues which helps to improve test reliability and reduce false failures


Sample TestNG Project Structure and its overview:


Project Root

├── src

│ ├── main

│ │ ├── java

│ │ └── resources

│ │

│ └── test

│ ├── java

│ │ ├── Hooks

│ │ │ └── Hooks.java

│ │ │

│ │ ├── driver

│ │ │ └── DriverFactory.java

│ │ │

│ │ ├── listeners

│ │ │ ├── RetryAnalyser.java

│ │ │ ├── RetryListener.java

│ │ │ └── TestListener.java

│ │ │

│ │ ├── pageObjects

│ │ │ ├── LoginPage.java

│ │ │ └── RegisterPage.java

│ │ │

│ │ └── suite

│ │ ├── LoginPageTest.java

│ │ └── RegisterDataTest.java

│ │

│ │ ├── utilities

│ │ │ ├── ConfigReader.java

│ │ │ ├── ElementUtils.java

│ │ │ ├── ExcelSheetHandling.java

│ │ │ └── TestDataProvider.java

│ │ │

│ └── resources

│ ├── ExcelSheet

│ │ └── TestData1.xlsx

│ │

│ └── properties

│ └── config.properties

├── test-output

│ ├── index.html

│ ├── emailable-report.html

│ ├── testng-results.xml

│ └── (other report files)

├── pom.xml

└── testng.xml


Hooks

Hooks class contains common setup and teardown functionality required before and after test execution.

Driver

Driver Factory class ensures that driver setup is handled from one central place, which is responsible for browser initialization and WebDriver management making the framework more maintainable and reusable

Listeners

Listener package contains TestNG listener classes such as Retry Analyser, Retry Listener, and Test Listener. if a test fails due to a temporary issue, the retry logic can automatically rerun that test.

page Objects

Each class in this package represents a specific page of the application. This improves code reusability and reduces duplication. All web elements and page-specific methods are maintained inside these classes.

Suite

Suite package contains the actual TestNG test classes. These classes contain the test methods, and execution flow for validating each module of the application

Utilities

utilities package contains common reusable helper classes

pom.xml

TestNG uses the pom.xml file (in Maven projects) to manage dependencies, plugins, and test execution settings in a centralized way. It allows easy integration of libraries like TestNG and Selenium without manual setup. Overall, it simplifies build management and enhances automation flexibility

testng.xml

The testng.xml file is an important configuration file used in the TestNG framework. It controls how the test suite is executed and allowing testers to manage suites, groups, parameters, and execution flow without modifying the actual test scripts.


Once you understand the basics of TestNG such as annotations, test execution, and reporting, you can start building the automation frameworks using Page Object Model, data-driven testing, and parallel execution.

With practice, TestNG becomes an essential tool for delivering efficient and reliable automated tests.


Happy Learning.


+1 (302) 200-8320

NumPy_Ninja_Logo (1).png

Numpy Ninja Inc. 8 The Grn Ste A Dover, DE 19901

© Copyright 2025 by Numpy Ninja Inc.

  • Twitter
  • LinkedIn
bottom of page