testng-parallel
Use when configuring parallel test execution with TestNG including thread pools, suite configuration, and synchronization.
What this skill does
# TestNG Parallel Execution
Master TestNG parallel test execution including thread pool configuration, suite-level parallelism, method-level parallelism, and thread safety patterns. This skill covers techniques for maximizing test throughput while maintaining test reliability.
## Overview
TestNG supports parallel execution at multiple levels: suite, test, class, and method. Proper parallel configuration can significantly reduce test execution time, but requires careful consideration of thread safety and resource management.
## Parallel Execution Modes
### Suite-Level Parallelism
Run multiple `<test>` tags in parallel:
```xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Parallel Suite" parallel="tests" thread-count="3">
<test name="Chrome Tests">
<classes>
<class name="com.example.tests.BrowserTest"/>
</classes>
</test>
<test name="Firefox Tests">
<classes>
<class name="com.example.tests.BrowserTest"/>
</classes>
</test>
<test name="Safari Tests">
<classes>
<class name="com.example.tests.BrowserTest"/>
</classes>
</test>
</suite>
```
### Class-Level Parallelism
Run test classes in parallel:
```xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Parallel Classes" parallel="classes" thread-count="4">
<test name="All Tests">
<classes>
<class name="com.example.tests.UserServiceTest"/>
<class name="com.example.tests.ProductServiceTest"/>
<class name="com.example.tests.OrderServiceTest"/>
<class name="com.example.tests.PaymentServiceTest"/>
</classes>
</test>
</suite>
```
### Method-Level Parallelism
Run test methods in parallel:
```xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Parallel Methods" parallel="methods" thread-count="5">
<test name="Service Tests">
<classes>
<class name="com.example.tests.IndependentMethodsTest"/>
</classes>
</test>
</suite>
```
### Instance-Level Parallelism
Run test instances in parallel (useful with Factory):
```xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Parallel Instances" parallel="instances" thread-count="3">
<test name="Factory Tests">
<classes>
<class name="com.example.tests.FactoryGeneratedTest"/>
</classes>
</test>
</suite>
```
## Thread Pool Configuration
### Basic Thread Configuration
```xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Thread Pool Suite" parallel="methods" thread-count="10">
<!-- Global thread pool configuration -->
<test name="Test Group 1" thread-count="5">
<!-- Override for this specific test -->
<classes>
<class name="com.example.tests.Test1"/>
</classes>
</test>
<test name="Test Group 2">
<!-- Uses suite-level thread-count -->
<classes>
<class name="com.example.tests.Test2"/>
</classes>
</test>
</suite>
```
### Data Provider Parallel Execution
```xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="DataProvider Suite" data-provider-thread-count="20">
<test name="Data Driven Tests">
<classes>
<class name="com.example.tests.ParallelDataProviderTest"/>
</classes>
</test>
</suite>
```
```java
public class ParallelDataProviderTest {
@DataProvider(name = "largeDataSet", parallel = true)
public Object[][] provideLargeDataSet() {
Object[][] data = new Object[100][2];
for (int i = 0; i < 100; i++) {
data[i] = new Object[]{"User" + i, "user" + i + "@example.com"};
}
return data;
}
@Test(dataProvider = "largeDataSet")
public void testWithParallelData(String name, String email) {
System.out.println(Thread.currentThread().getName() + " - Testing: " + name);
// Each data row runs in parallel
}
}
```
## Thread Safety Patterns
### Thread-Local Storage
```java
import org.testng.annotations.*;
public class ThreadLocalTest {
// Thread-local storage for test-specific resources
private static ThreadLocal<WebDriver> driverThread = new ThreadLocal<>();
private static ThreadLocal<String> sessionThread = new ThreadLocal<>();
@BeforeMethod
public void setUp() {
// Initialize thread-local resources
driverThread.set(createWebDriver());
sessionThread.set(generateSessionId());
}
@AfterMethod
public void tearDown() {
// Clean up thread-local resources
WebDriver driver = driverThread.get();
if (driver != null) {
driver.quit();
}
driverThread.remove();
sessionThread.remove();
}
@Test
public void testParallelBrowser() {
WebDriver driver = driverThread.get();
String session = sessionThread.get();
System.out.println("Thread: " + Thread.currentThread().getName() +
" Session: " + session);
// Use thread-local driver
}
private WebDriver createWebDriver() {
// Create browser instance
return new ChromeDriver();
}
private String generateSessionId() {
return UUID.randomUUID().toString();
}
}
```
### Synchronized Shared Resources
```java
import org.testng.annotations.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.ConcurrentHashMap;
public class SynchronizedResourceTest {
// Thread-safe counter
private static AtomicInteger testCounter = new AtomicInteger(0);
// Thread-safe collection
private static ConcurrentHashMap<String, String> sharedCache = new ConcurrentHashMap<>();
// Lock object for critical sections
private static final Object lock = new Object();
@Test(threadPoolSize = 5, invocationCount = 100)
public void testAtomicOperations() {
int count = testCounter.incrementAndGet();
System.out.println("Test count: " + count);
}
@Test(threadPoolSize = 3, invocationCount = 50)
public void testConcurrentMap() {
String threadName = Thread.currentThread().getName();
sharedCache.put(threadName, String.valueOf(System.currentTimeMillis()));
// Thread-safe without explicit synchronization
}
@Test(threadPoolSize = 2, invocationCount = 10)
public void testSynchronizedBlock() {
synchronized (lock) {
// Critical section - only one thread at a time
performCriticalOperation();
}
}
private void performCriticalOperation() {
// Operations that require exclusive access
}
}
```
### Immutable Test Data
```java
import java.util.Collections;
import java.util.List;
import java.util.Arrays;
public class ImmutableDataTest {
// Immutable test data - inherently thread-safe
private static final List<String> TEST_USERS = Collections.unmodifiableList(
Arrays.asList("user1", "user2", "user3", "user4", "user5")
);
private static final Map<String, String> CONFIG = Collections.unmodifiableMap(
Map.of(
"url", "https://api.example.com",
"timeout", "30000",
"retries", "3"
)
);
@Test(threadPoolSize = 5, invocationCount = 20)
public void testWithImmutableData() {
// Safe to read from multiple threads
int userIndex = ThreadLocalRandom.current().nextInt(TEST_USERS.size());
String user = TEST_USERS.get(userIndex);
String url = CONFIG.get("url");
System.out.println(Thread.currentThread().getName() +
" - User: " + user + ", URL: " + url);
}
}
```
## Test Isolation Patterns
### Independent Test Methods
```java
public class IndependentTestsExample {
// Each test method is completely independent
@Test
public void teRelated in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.