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".
What this skill does
# TestNG Testing Skill
## Core Patterns
### Basic Test with Groups
```java
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
```java
@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
```xml
<!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
```xml
<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
```java
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
```java
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
| Bad | Good | Why |
|-----|------|-----|
| `dependsOnMethods` everywhere | Independent tests | Cascading failures |
| No groups | `@Test(groups = "smoke")` | Can't run subsets |
| Hard-coded test data | `@DataProvider` | Reusable |
| Priority ordering | Independent tests | Fragile |
## Quick Reference
| Task | Command |
|------|---------|
| Run suite | `mvn test -DsuiteXmlFile=testng.xml` |
| Run group | `mvn test -Dgroups=smoke` |
| Run class | `mvn test -Dtest=LoginTest` |
| Reports | `test-output/index.html` |
## Deep Patterns → `reference/playbook.md`
| § | Section | Lines |
|---|---------|-------|
| 1 | Project Setup & Configuration | Maven + Surefire config |
| 2 | Suite XML Configuration | Multi-env, parallel, groups |
| 3 | BaseTest & Thread-Safe Driver | ThreadLocal, ConfigReader |
| 4 | Data Providers (Advanced) | Excel, JSON, CSV, parallel, cross-class |
| 5 | Factory Pattern | Cross-browser matrix |
| 6 | Listeners (Production Suite) | Retry, screenshot, timing |
| 7 | Soft Assertions & Dependencies | Groups, method deps |
| 8 | Page Object Integration | PageFactory, fluent POs |
| 9 | Parallel Execution Strategies | Method/class/test/mixed |
| 10 | Reporting Integration | Allure, ExtentReports |
| 11 | CI/CD Integration | GitHub Actions, Jenkins |
| 12 | Debugging Quick-Reference | 12 common problems |
| 13 | Best Practices Checklist | 14 items |
Related in unit-testing
phpunit-skill
IncludedGenerates PHPUnit tests in PHP. Covers assertions, data providers, mocking, and test doubles. Use when user mentions "PHPUnit", "TestCase", "assertEquals", "PHP test". Triggers on: "PHPUnit", "TestCase PHP", "assertEquals PHP", "PHP unit test".
karma-skill
IncludedGenerates Karma test runner configurations for browser-based JavaScript testing. Works with Jasmine, Mocha, or QUnit. Use when user mentions "Karma", "karma.conf.js", "browser test runner". Triggers on: "Karma", "karma.conf", "karma test runner", "browser-based JS test".
unittest-skill
IncludedGenerates Python unittest tests. Built-in testing framework with TestCase, setUp/tearDown, and assertion methods. Use when user mentions "unittest", "TestCase", "self.assertEqual", "Python unittest". Triggers on: "unittest", "TestCase", "self.assertEqual", "Python unittest" (not pytest).
jest-skill
IncludedGenerates Jest unit and integration tests in JavaScript or TypeScript. Covers mocking, snapshots, async testing, and React component testing. Use when user mentions "Jest", "describe/it/expect", "jest.mock", "toMatchSnapshot". Triggers on: "Jest", "expect().toBe()", "jest.mock", "snapshot test", "JS test", "React test".
junit-5-skill
IncludedGenerates production-grade JUnit 5 unit and integration tests in Java. Covers assertions, parameterized tests, lifecycle hooks, mocking with Mockito, and nested tests. Use when user mentions "JUnit", "JUnit 5", "@Test", "assertEquals", "Assertions", "Java unit test". Triggers on: "JUnit", "@Test", "assertEquals", "Java test", "unit test Java".
mstest-skill
IncludedGenerates MSTest tests in C#. Microsoft's built-in testing framework for .NET. Use when user mentions "MSTest", "[TestMethod]", "[TestClass]", "Assert.AreEqual". Triggers on: "MSTest", "[TestMethod]", "[TestClass]", "Microsoft test framework".