Pairwise Test Generator Skill
This skill generates JUnit test cases using the Pairwise (All-Pairs) testing technique.
What is Pairwise Testing?
Pairwise testing reduces the number of test cases needed when testing combinations of multiple parameters. Instead of testing all possible combinations (which can be millions), pairwise testing ensures that every pair of parameter values is tested at least once.
Example:
- •8 factors with 5-1000 values each = 28,000,000 total combinations
- •Pairwise testing reduces this to ~300-500 test cases
- •Still achieves high coverage of defects (studies show 70-90% of bugs involve 2 factors)
When to Use This Skill
Use this skill when:
- •You have multiple input parameters (factors) with multiple possible values (levels)
- •Testing all combinations is impractical (too many test cases)
- •You need systematic coverage of parameter interactions
- •You're in an enterprise context where coverage must be demonstrated
How to Use
1. Annotate Your Java Model Class with @pairwise DSL
Add @pairwise annotations in Javadoc comments to define test factors and levels:
/** * @pairwise 0,1,2,3,4 * @pairwise-names Bronze,Silver,Gold,Platinum,Diamond */ private final int memberRank; /** * @pairwise-sample 000,100,200,300,400,500,600,700,800,900 * @pairwise-comment Sample 10 representative codes from 000-999 */ private final String campaignCode;
DSL Tags:
- •
@pairwise- Define test values (comma-separated) - •
@pairwise-sample- Define sample values for large ranges - •
@pairwise-names- Optional: descriptive names for values
2. Run the Skill
The skill will:
- •Automatically detect Java classes in
src/main/java - •Parse @pairwise annotations
- •Generate pairwise test combinations
- •Create JUnit test class
3. Execute Tests
Run tests and check coverage:
./gradlew test jacocoTestReport
Implementation
This skill uses the allpairspy Python library, which implements the PICT (Pairwise Independent Combinatorial Testing) algorithm developed by Microsoft.
Output
The skill generates:
- •A list of pairwise test case combinations (Fixtures)
- •A JUnit test class skeleton with
@ParameterizedTest - •Statistics showing reduction in test cases vs. exhaustive testing
IMPORTANT: After Pairwise Fixture Generation
YOU (the LLM) MUST implement the actual test logic!
The Python script only generates:
- •Pairwise test data combinations (fixtures)
- •Parameterized test method skeleton
- •TODO comments as placeholders
Your Responsibilities:
- •
Read the test target class (e.g.,
DiscountCalculator.java)- •Understand the business logic
- •Identify what methods need to be tested
- •Understand expected behavior
- •
Read the generated test class with TODO markers
- •
Implement test logic in the TODO section:
- •Call the target class methods with the context
- •Add appropriate assertions based on business rules
- •Verify expected behavior for all parameter combinations
Example Implementation Pattern:
void testCalculation(...parameters...) {
// Arrange (already generated by script)
PurchaseContext context = new PurchaseContext(...);
// Act - YOU MUST ADD THIS
double discountRate = calculator.calculateDiscountRate(context);
int points = calculator.calculatePoints(context);
// Assert - YOU MUST ADD THIS
assertTrue(discountRate >= 0.0 && discountRate <= 1.0);
assertTrue(points >= 0);
// Add more specific assertions based on business logic
}
After Implementation:
Execute tests and verify coverage:
./gradlew test jacocoTestReport
Goal: Achieve 90%+ coverage with pairwise-generated test cases