#1 India's Top IT Training Institute

On Demand Courses

9 programs

×

About Uncodemy

Know more about who we are and what we stand for.

About Us

About Us

Discover our mission to equip individuals with essential IT skills and industry expertise.

Read More →
UnCodeMy Gallery

UnCodeMy Gallery

Explore highlights from our IT training sessions and success stories.

Read More →
×

Free Resources

Learn, practice and plan your career — bilkul free.

Tutorials

Tutorials

Step-by-step written tutorials to learn any technology at your own pace.

Read More →
Free Counselling

Free Counselling

Book a free video counselling session and pick the right course for you.

Read More →
Online Compiler

Online Compiler

Write, run and test your code online — no setup required.

Read More →

Automation Testing TestNG Guide
PDF Downloads

Download the TestNG guide PDF from Uncodemy: annotations, assertions, data providers, parallel runs and testng.xml with Selenium examples.

Prepared by: Uncodemy trainer team Reviewed by: Uncodemy Last reviewed: 26 Oct 2026
TestNG at a Glance
1
Annotations@Test, @BeforeMethod, @AfterMethod, @DataProvider and more.
2
AssertionsHard assert vs soft assert for independent checks.
3
Data providersSupply rows of data; test runs once per row.
4
Groups & priorityTag tests (smoke, regression) and control order.
5
Parallel executionRun methods/classes/tests in parallel with thread-safe drivers.
6
testng.xmlSuite file: selects classes, groups, parallel config.

Quick Answer

This page offers Uncodemy's TestNG guide as a PDF download. TestNG is a Java testing framework widely used with Selenium for organising, running and reporting automated tests. The guide covers the main annotations, assertions, data providers, grouping, parallel execution and the testng.xml suite file.

Download

TestNG Guide PDFs

Three quick-access entry points into the same TestNG guide PDF: the full guide, the annotations + data provider pack, and the testng.xml + parallel execution reference. All PDFs on this page are free to download. No form is required.

3 PDFs Available
PDF 01 Main Guide

Automation Testing TestNG Guide

The complete guide to TestNG — what it is, common annotations, a Selenium example, assertions, grouping, reports, common mistakes and Selenium waits comparison.

[N] pages [X] MB Oct 2026
Download PDF
PDF 02 Code Example

Annotations & Data Provider Pack

A worked Selenium test using @BeforeMethod, @Test and @AfterMethod, plus a @DataProvider example that runs the same test once per row of test data.

[N] pages [X] MB Oct 2026
Download PDF
PDF 03 Suite & Parallel

testng.xml & Parallel Execution Pack

A complete testng.xml example with groups and parallel config, plus thread-safety tips (ThreadLocal drivers), reports overview and a scalable folder structure.

[N] pages [X] MB Oct 2026
Download PDF

All three download buttons open the same TestNG guide PDF file. By downloading, you agree to our Privacy Policy. These PDFs are study material only — not a certificate or job guarantee.

00

What is TestNG?

TestNG is an open-source testing framework for Java, inspired by JUnit and NUnit, with extra features that suit end-to-end and integration testing. It provides annotations to mark test methods and setup steps, assertions to check results, flexible grouping and ordering, data-driven testing and built-in support for running tests in parallel. TestNG itself does not drive a browser; it is typically paired with Selenium WebDriver, which controls the browser, while TestNG structures the tests and reports the results. Many automation testing job descriptions for Java still mention TestNG, so it is worth understanding even if you later learn newer tools.

01

Common TestNG annotations

Annotation Runs Typical use
@Test As a test method Marks a method as a test
@BeforeSuite / @AfterSuite Once before or after the whole suite Global setup such as reading configuration
@BeforeTest / @AfterTest Before or after tests in a testng.xml test tag Group-level setup
@BeforeClass / @AfterClass Once before or after the class Start and close a browser for the class
@BeforeMethod / @AfterMethod Before or after each test method Open a page, take screenshots on failure
@DataProvider Supplies data to a test Data-driven testing
@Parameters Receives values from testng.xml Browser name or base URL
02

A simple TestNG test with Selenium

Illustrative structure only. It assumes Selenium and TestNG are on the project classpath and uses a public demo site; adapt locators to your application.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.*;

public class LoginTest {
    private WebDriver driver;

    @BeforeMethod
    public void setup() {
        driver = new ChromeDriver();
        driver.get("https://example.com/login");
    }

    @Test(groups = "smoke")
    public void validateLoginShowsDashboard() {
        driver.findElement(By.id("email")).sendKeys("test.user@example.com");
        driver.findElement(By.id("password")).sendKeys("your-test-password");
        driver.findElement(By.id("login")).click();
        Assert.assertEquals(
            driver.getCurrentUrl().contains("dashboard"),
            true,
            "User should land on the dashboard"
        );
    }

    @AfterMethod(alwaysRun = true)
    public void tearDown() {
        if (driver != null) driver.quit();
    }
}
03

Assertions

Type Behaviour Use when
Hard assert (Assert class) Stops the test at the first failure A later step makes no sense if this fails
Soft assert (SoftAssert) Collects failures and reports them at assertAll() Several independent checks on one page
assertEquals, assertTrue, assertNotNull Common checks Comparing values, conditions and objects
04

Data-driven testing with a DataProvider

A data provider supplies rows of data, and the test method runs once for each row.

@DataProvider(name = "loginData")
public Object[][] loginData() {
    return new Object[][] {
        {"valid.user@example.com", "ValidPass#1", true},
        {"valid.user@example.com", "wrong-pass",   false},
        {"",                        "",             false}
    };
}

@Test(dataProvider = "loginData")
public void loginScenarios(String email, String password, boolean shouldSucceed) {
    // enter credentials, submit, then assert the expected outcome
}
05

testng.xml suite file

The suite file selects which tests, groups or classes run, and can set parallel execution.

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="RegressionSuite" parallel="classes" thread-count="3">
  <test name="Smoke">
    <groups>
      <run>
        <include name="smoke"/>
      </run>
    </groups>
    <classes>
      <class name="tests.LoginTest"/>
    </classes>
  </test>
</suite>
06

Useful TestNG features

  • → Groups: tag tests such as smoke or regression and run only those.
  • → Dependencies: dependsOnMethods can order tests, though independent tests are preferable.
  • → Priority: controls order within a class; use sparingly.
  • → Parallel execution: run methods, classes or tests in parallel to save time; keep tests independent and drivers thread-safe.
  • → Listeners: react to events such as failure, for example to capture a screenshot.
  • → Retry analyzer: re-run failed tests a limited number of times, visibly.
07

Parallel execution and thread safety

Running tests in parallel can cut execution time sharply, but only if tests do not share mutable state. A single static WebDriver shared across threads will cause tests to interfere with each other. A common approach is to store the driver in a ThreadLocal so each thread has its own browser, and to keep test data unique per test. Start with a small thread count, watch for instability and increase carefully.

08

Reports

Output Notes
Default HTML and XML reports Generated in the output folder after every run
Surefire reports Produced when TestNG runs through Maven
Third-party report tools Many teams add richer HTML reports with screenshots
09

Common mistakes

What to avoid

  • One shared static driver with parallel tests.
  • Heavy use of dependsOnMethods creating fragile chains.
  • Fixed sleeps instead of explicit waits.
  • Credentials in the code instead of configuration or secrets.
  • Tests that depend on execution order.
10

Selenium waits compared

Wait type Behaviour Advice
Implicit wait Global polling for elements to appear Avoid mixing with explicit waits
Explicit wait Waits for a specific condition on one element Preferred for most cases
Fluent wait Explicit wait with custom polling and ignored exceptions Use for special timing cases
Thread.sleep Fixed pause Avoid; slows tests and still fails randomly
11

Interview-style quick answers

  • → Difference between @BeforeTest and @BeforeMethod: the first runs once before the testng.xml test tag, the second before every test method.
  • → How to skip a test: use enabled=false or throw SkipException.
  • → How to run only some tests: use groups or select classes in testng.xml.
12

Folder structure that scales

  • → src/main/java/pages: page objects.
  • → src/test/java/tests: test classes.
  • → src/test/resources: testng.xml, configuration and test data.
  • → utils: driver factory, readers, listeners.

Learn with a trainer

Ready to build TestNG frameworks that scale with parallel runs and clean reports? Explore Uncodemy's Software Testing course or book a free demo and learn from industry trainers.

View Course
About these PDFs: These PDFs are study material for learning and revision. They are not a certificate, a degree or a promise of a job, and technology changes, so check official documentation for the latest details. Spot an error? Write to info@uncodemy.com and the trainer team will review it.
FAQ

Frequently Asked Questions

What is TestNG?
TestNG is a Java testing framework that organises, runs and reports automated tests, often used together with Selenium WebDriver.
What is the difference between TestNG and JUnit?
Both are Java test frameworks. TestNG offers built-in groups, data providers, flexible dependency and parallel configuration, while JUnit 5 has its own extension model and parameterised tests. Many teams use either.
What is testng.xml?
It is a suite configuration file that defines which classes, groups and tests to run and how, including parallel execution.
What is a DataProvider in TestNG?
A DataProvider is a method that supplies multiple sets of data to a test method, which runs once for each set.
How do I run TestNG tests in parallel?
Set the parallel and thread-count attributes in testng.xml, and make sure tests are independent and each thread has its own WebDriver.
Are these PDFs free to download?
Yes. All TestNG guide PDFs on this page are free to download. No form is required — just click the download button on any card above. If a form is ever introduced, a consent checkbox and a link to our Privacy Policy will be added in line with the DPDP Act 2023.