Testng Skill

Generates TestNG tests in Java with groups, data providers, parallel execution, XML suite configuration, and listeners. Use when user mentions "TestNG", "@DataProvider", "testng.xml", "groups". Triggers on: "TestNG", "@DataProvider", "testng.xml", "TestNG suite", "parallel tests Java".

Published by @LambdaTest·from LambdaTest/agent-skills·0 agent reads / 30d·0 saves·

TestNG Testing Skill

Core Patterns

Basic Test with Groups

import org.testng.annotations.*;
import org.testng.Assert;

public class LoginTest {
    @BeforeMethod
    public void setUp() { /* setup */ }

    @Test(groups = "smoke")
    public void testLoginSuccess() {
        Assert.assertTrue(loginService.login("[email protected]", "password123"));
    }

    @Test(groups = "regression", dependsOnMethods = "testLoginSuccess")
    public void testAccessDashboard() {
        Assert.assertNotNull(dashboard.getContent());
    }

    @Test(expectedExceptions = AuthenticationException.class)
    public void testLoginInvalidPassword() {
        loginService.login("[email protected]", "wrong");
    }

    @AfterMethod
    public void tearDown() { /* cleanup */ }
}

Data Providers

@DataProvider(name = "loginData")
public Object[][] loginData() {
    return new Object[][] {
        {"[email protected]", "admin123", true},
        {"[email protected]", "password", true},
        {"[email protected]", "wrong", false},
    };
}

@Test(dataProvider = "loginData")
public void testLogin(String email, String password, boolean expected) {
    Assert.assertEquals(loginService.login(email, password), expected);
}

TestNG XML Suite

<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Regression" parallel="tests" thread-count="5">
  <test name="Smoke">
    <groups><run><include name="smoke"/></run></groups>
    <classes><class name="tests.LoginTest"/></classes>
  </test>
  <test name="Full">
    <groups><run><include name="regression"/><exclude name="flaky"/></run></groups>
    <packages><package name="tests.*"/></packages>
  </test>
</suite>

Parallel Execution

<suite parallel="methods" thread-count="5">   <!-- Method level -->
<suite parallel="classes" thread-count="5">    <!-- Class level -->
<suite parallel="tests" thread-count="5">      <!-- Test level -->

Soft Assertions

SoftAssert soft = new SoftAssert();
soft.assertEquals(user.getName(), "Alice");
soft.assertEquals(user.getAge(), 25);
soft.assertTrue(user.isActive());
soft.assertAll();  // Reports all failures at once

Listeners

public class TestListener implements ITestListener {
    @Override public void onTestFailure(ITestResult result) {
        System.out.println("Failed: " + result.getName());
        // Take screenshot, log, etc.
    }
}

@Listeners(TestListener.class)
public class LoginTest { /* ... */ }

Lifecycle Annotations

@BeforeSuite → @BeforeTest → @BeforeClass → @BeforeMethod → @Test → @AfterMethod → @AfterClass → @AfterTest → @AfterSuite

Anti-Patterns

BadGoodWhy
dependsOnMethods everywhereIndependent testsCascading failures
No groups@Test(groups = "smoke")Can't run subsets
Hard-coded test data@DataProviderReusable
Priority orderingIndependent testsFragile

Quick Reference

TaskCommand
Run suitemvn test -DsuiteXmlFile=testng.xml
Run groupmvn test -Dgroups=smoke
Run classmvn test -Dtest=LoginTest
Reportstest-output/index.html

Deep Patterns → reference/playbook.md

§SectionLines
1Project Setup & ConfigurationMaven + Surefire config
2Suite XML ConfigurationMulti-env, parallel, groups
3BaseTest & Thread-Safe DriverThreadLocal, ConfigReader
4Data Providers (Advanced)Excel, JSON, CSV, parallel, cross-class
5Factory PatternCross-browser matrix
6Listeners (Production Suite)Retry, screenshot, timing
7Soft Assertions & DependenciesGroups, method deps
8Page Object IntegrationPageFactory, fluent POs
9Parallel Execution StrategiesMethod/class/test/mixed
10Reporting IntegrationAllure, ExtentReports
11CI/CD IntegrationGitHub Actions, Jenkins
12Debugging Quick-Reference12 common problems
13Best Practices Checklist14 items

Bundled with this artifact

2 files

Reference files that ship alongside this artifact. Agents pull these in only when the task needs them.

More on the bench

SKILL0

Skill Creator

Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.

ai-prompt-engineering+1
6
SKILL0

Bash Pro

Master of defensive Bash scripting for production automation, CI/CD pipelines, and system utilities. Expert in safe, portable, and testable shell scripts.

ai-prompt-engineering+3
4
SKILL0

Documentation

Creates, structures, and reviews technical documentation following the Diátaxis framework (tutorials, how-to guides, reference, and explanation pages). Use when a user needs to write or reorganize docs, structure a tutorial vs. a how-to guide, build reference docs or API documentation, create explanation pages, choose between Diátaxis documentation types, or improve existing documentation structure. Trigger terms include: documentation structure, Diátaxis, tutorials vs how-to guides, organize docs, user guide, reference docs, technical writing.

software-engineering
4