testng-fundamentals
Use when working with TestNG annotations, assertions, test lifecycle, and configuration for Java testing.
What this skill does
# TestNG Fundamentals
Master TestNG fundamentals including annotations, assertions, test lifecycle, and XML configuration for Java testing. This skill provides comprehensive coverage of essential concepts, patterns, and best practices for professional TestNG development.
## Overview
TestNG is a powerful testing framework for Java inspired by JUnit and NUnit, designed to cover a wider range of test categories: unit, functional, end-to-end, and integration testing. It supports annotations, data-driven testing, parameterization, and parallel execution.
## Installation and Setup
### Maven Configuration
Add TestNG to your Maven project:
```xml
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>7.9.0</version>
<scope>test</scope>
</dependency>
```
Configure the Surefire plugin for TestNG:
```xml
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
```
### Gradle Configuration
Add TestNG to your Gradle project:
```groovy
dependencies {
testImplementation 'org.testng:testng:7.9.0'
}
test {
useTestNG()
}
```
## Core Annotations
### Test Lifecycle Annotations
TestNG provides comprehensive lifecycle annotations:
```java
import org.testng.annotations.*;
public class LifecycleTest {
@BeforeSuite
public void beforeSuite() {
// Runs once before the entire test suite
System.out.println("Before Suite");
}
@AfterSuite
public void afterSuite() {
// Runs once after the entire test suite
System.out.println("After Suite");
}
@BeforeTest
public void beforeTest() {
// Runs before each <test> tag in testng.xml
System.out.println("Before Test");
}
@AfterTest
public void afterTest() {
// Runs after each <test> tag in testng.xml
System.out.println("After Test");
}
@BeforeClass
public void beforeClass() {
// Runs once before the first test method in the class
System.out.println("Before Class");
}
@AfterClass
public void afterClass() {
// Runs once after the last test method in the class
System.out.println("After Class");
}
@BeforeMethod
public void beforeMethod() {
// Runs before each test method
System.out.println("Before Method");
}
@AfterMethod
public void afterMethod() {
// Runs after each test method
System.out.println("After Method");
}
@Test
public void testMethod() {
System.out.println("Test Method");
}
}
```
### Test Annotation Attributes
The `@Test` annotation supports various attributes:
```java
public class TestAttributesExample {
@Test(description = "Verifies user login functionality")
public void testLogin() {
// Test with description
}
@Test(enabled = false)
public void disabledTest() {
// This test will not run
}
@Test(priority = 1)
public void firstTest() {
// Runs first (lower priority = earlier execution)
}
@Test(priority = 2)
public void secondTest() {
// Runs second
}
@Test(groups = {"smoke", "regression"})
public void groupedTest() {
// Test belongs to multiple groups
}
@Test(dependsOnMethods = {"testLogin"})
public void testDashboard() {
// Runs only if testLogin passes
}
@Test(dependsOnGroups = {"setup"})
public void dependentTest() {
// Runs only if all tests in "setup" group pass
}
@Test(timeOut = 5000)
public void timedTest() {
// Fails if takes more than 5 seconds
}
@Test(invocationCount = 3)
public void repeatedTest() {
// Runs 3 times
}
@Test(invocationCount = 100, threadPoolSize = 10)
public void parallelRepeatedTest() {
// Runs 100 times across 10 threads
}
@Test(expectedExceptions = IllegalArgumentException.class)
public void exceptionTest() {
throw new IllegalArgumentException("Expected");
}
@Test(expectedExceptions = RuntimeException.class,
expectedExceptionsMessageRegExp = ".*invalid.*")
public void exceptionWithMessageTest() {
throw new RuntimeException("This is invalid input");
}
}
```
## Assertions
### Basic Assertions
TestNG provides comprehensive assertion methods:
```java
import org.testng.Assert;
import org.testng.annotations.Test;
public class AssertionExamples {
@Test
public void testBasicAssertions() {
// Equality
Assert.assertEquals(5, 5);
Assert.assertEquals("hello", "hello");
Assert.assertEquals(new int[]{1, 2, 3}, new int[]{1, 2, 3});
// Boolean
Assert.assertTrue(true);
Assert.assertFalse(false);
// Null checks
Assert.assertNull(null);
Assert.assertNotNull("value");
// Same reference
String s1 = "test";
String s2 = s1;
Assert.assertSame(s1, s2);
Assert.assertNotSame(new String("test"), new String("test"));
}
@Test
public void testAssertionsWithMessages() {
// Assertions with custom failure messages
Assert.assertEquals(5, 5, "Values should be equal");
Assert.assertTrue(true, "Condition should be true");
Assert.assertNotNull("value", "Value should not be null");
}
@Test
public void testCollectionAssertions() {
// Array assertions
String[] expected = {"a", "b", "c"};
String[] actual = {"a", "b", "c"};
Assert.assertEquals(actual, expected);
// Unordered comparison
String[] array1 = {"a", "b", "c"};
String[] array2 = {"c", "a", "b"};
Assert.assertEqualsNoOrder(array1, array2);
}
}
```
### Soft Assertions
Soft assertions allow multiple assertions to be collected before failing:
```java
import org.testng.annotations.Test;
import org.testng.asserts.SoftAssert;
public class SoftAssertExample {
@Test
public void testWithSoftAssert() {
SoftAssert softAssert = new SoftAssert();
// All assertions are executed
softAssert.assertEquals(1, 1, "First check");
softAssert.assertEquals(2, 3, "Second check - will fail");
softAssert.assertTrue(false, "Third check - will fail");
softAssert.assertNotNull(null, "Fourth check - will fail");
// Report all failures at the end
softAssert.assertAll();
}
}
```
## TestNG XML Configuration
### Basic testng.xml Structure
```xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="My Test Suite" verbose="1">
<test name="Unit Tests">
<classes>
<class name="com.example.tests.UserServiceTest"/>
<class name="com.example.tests.ProductServiceTest"/>
</classes>
</test>
<test name="Integration Tests">
<packages>
<package name="com.example.integration.*"/>
</packages>
</test>
</suite>
```
### Group Configuration
```xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Group Suite">
<test name="Smoke Tests">
<groups>
<run>
<include name="smoke"/>
</run>
</groups>
<packages>
<package name="com.example.tests.*"/>
</packages>
</test>
<test name="Regression Tests">
<groups>
<run>
<include name="regression"/>
<exclude name="broken"/>
</run>
</groups>
<packages>
<package name="com.example.tests.*"/>
</packages>
</test>
</suite>
```
### Parameters in testng.xml
```xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="PaRelated in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.