Unit Test Suite Generator with Edge Cases
Generate comprehensive, mutation-tested unit tests with AAA pattern, boundary cases, and proper mock boundaries.
Interactive Prompt Playground
{{CODE}}{{FRAMEWORK}}{{MOCK_LIB}}You are a Principal Software Engineer in Test (SDET) and TDD master.
Generate a comprehensive, production-grade unit test suite for the following code:
```
export class PricingCalculator {
calculateTotal(items: CartItem[], userTier: UserTier, couponCode?: string): CalculationResult {
if (items.length === 0) throw new EmptyCartError("Cannot calculate pricing for empty cart");
let subtotal = items.reduce((sum, item) => sum + (item.price * item.quantity), 0);
let discount = 0;
if (userTier === 'VIP') discount += subtotal * 0.15;
if (couponCode === 'SAVE20' && subtotal >= 100) discount += 20;
const taxableAmount = Math.max(0, subtotal - discount);
const tax = taxableAmount * 0.08;
return { subtotal, discount, tax, total: taxableAmount + tax };
}
}
```
Testing Framework: Vitest (TypeScript)
Mocking Library: Vitest vi.fn() and vi.spyOn()
Coverage & Quality Goals: 100% branch/statement coverage, defensive edge case verification.
Produce a test suite adhering to these standards:
1. **Arrange-Act-Assert (AAA) Pattern**:
- Ensure every test is clean, readable, and isolates a single behavior.
- Use descriptive test names (`should_<expectedBehavior>_when_<condition>`).
2. **Boundary & Malicious Input Matrix**:
- Empty collections, null/undefined inputs, zero, negative numbers, max integer bounds.
- Malformed strings, Unicode characters, and unexpected whitespace.
3. **Mock Isolation**:
- Mock external I/O (databases, network calls, file systems) strictly at domain boundaries.
- Avoid over-mocking internal domain logic or value objects.
4. **Failure & Exception Branches**:
- Test every exception thrown, verifying both exception type and message content.
Output the complete, runnable test file code with clear comments.How to Use This Prompt
- Paste the function, service, or component you want to test.
- Specify your test runner (Vitest, JUnit 5, Pytest).
- Receive a complete, runnable test file covering all branches and edge cases.
Engineering Tips & Best Practices
- Use parameterized / table-driven tests (@ParameterizedTest in JUnit, it.each in Vitest) to test large matrices cleanly.
What This Prompt Inspects
Key failure modes, design principles, and quality standards evaluated during execution.
Boundary Value Testing
Tests exact threshold cutoffs (e.g. subtotal = 99.99 vs 100.00).
AAA Structure
Maintains clear Arrange, Act, and Assert visual separation in every test.
Exception Assertions
Verifies custom error classes and messages on illegal states.
SprintKit Workflow Integrations
Complementary interactive tools and workflows across SprintKit to accelerate your engineering process.
Related Prompts
Explore related developer prompts in this workflow domain.
Integration & Contract Test Plan (Testcontainers / Playwright)
Create robust integration test suites with real databases in Docker containers and contract verification.
Flaky Test & Async Timing Race Condition Debugger
Fix nondeterministic test failures, unhandled async promises, and race conditions in Playwright, Jest, or Vitest.
TypeScript Strict Type Safety & Clean Code Review
Audit TypeScript code for type safety, type narrowing, generics, mutation traps, and runtime boundary leaks.