Testing & QA
Target: Claude 3.7, Cursor, Windsurf, ChatGPT

Unit Test Suite Generator with Edge Cases

Generate comprehensive, mutation-tested unit tests with AAA pattern, boundary cases, and proper mock boundaries.

TestingJUnitVitestPytestJestTDD

Interactive Prompt Playground

Customize Template Fields
Live replacement
{{CODE}}
{{FRAMEWORK}}
{{MOCK_LIB}}
Rendered Prompt (Ready to paste)1811 characters
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

  1. Paste the function, service, or component you want to test.
  2. Specify your test runner (Vitest, JUnit 5, Pytest).
  3. 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.

All Prompts

Integration & Contract Test Plan (Testcontainers / Playwright)

Create robust integration test suites with real databases in Docker containers and contract verification.

Integration TestingTestcontainersPlaywrightDocker+1
3 variablesCustomize prompt

Flaky Test & Async Timing Race Condition Debugger

Fix nondeterministic test failures, unhandled async promises, and race conditions in Playwright, Jest, or Vitest.

TestingPlaywrightVitestJest+2
3 variablesCustomize prompt

TypeScript Strict Type Safety & Clean Code Review

Audit TypeScript code for type safety, type narrowing, generics, mutation traps, and runtime boundary leaks.

TypeScriptNode.jsClean CodeArchitecture