---
name: unit-test-architect
description: "Plans the unit tests for a module before any are written: a test-case table per critical function, the mocking strategy and its boundaries, coverage targets, and one worked test per function to copy the pattern from. Use when a module has no tests yet and you need a test plan with cases per function, a mocking strategy, and a worked example in your framework. Do not use for generating a full test file for one function, or analysing the results of an existing suite. Related topics: coding, unit."
---

# Unit Test Architect

Plans the unit tests for a module before any are written: a test-case table per critical function, the mocking strategy and its boundaries, coverage targets, and one worked test per function to copy the pattern from.

## When to use

Use this skill when a module has no tests yet and you need a test plan with cases per function, a mocking strategy, and a worked example in your framework. Do not use it for generating a full test file for one function, or analysing the results of an existing suite.

## Workflow

1. Ask the user for each input listed below in a single message, skipping any they have already given. Where options are listed, offer them, but accept other answers too.
2. Enumerate the behaviours per critical function: happy path, boundaries, error branches, and external dependencies; each has a row.
3. Fix the mock boundary (process-crossing dependencies mocked, pure logic real) and express it in the chosen approach and framework idiom.
4. Assign a coverage target per function weighted toward error handling and data processing, summing to the overall target.
5. Write one complete arrange-act-assert test per critical function with the mock set up as the guidelines say.
6. Assemble the four sections and check every table row has a test name that reads as a sentence.

## Inputs

- **Programming language** (choose one: Python, JavaScript, TypeScript, Java, C#, Go)
- **Test framework** (choose one: pytest, Jest, Vitest, JUnit, NUnit, Go test)
- **Module description** (longer free text)
- **Module source if available** (longer free text)
- **Critical functions** (choose any: Initialization, Data processing, Output generation, Error handling, External calls)
- **Target coverage in percent** (number from 50 to 100)
- **Mocking approach** (choose one: Manual stubs, Mock library, Dependency injection)
- **Constraints** (longer free text)

## Output

A markdown document with Overview, Test Plan Table (function, case, mock, coverage), Sample Test Code (one fenced test per critical function), and Mock Guidelines.

## Prompt template

Fill the inputs into this template and follow it as the full instruction.

### Unit Test Architect

Design the unit test suite for the module below and provide the starter code.

- Programming language: {{Programming language}}
- Test framework: {{Test framework}}
- Module description: {{Module description}}
- Module source if available: {{Module source if available}}
- Critical functions: {{Critical functions}}
- Target coverage in percent: {{Target coverage in percent}}
- Mocking approach: {{Mocking approach}}
- Constraints: {{Constraints}}

Start from the module's responsibilities, not its lines. For each critical function, enumerate the behaviours worth a test: the happy path, each boundary, each error branch, and each external dependency it touches. Decide the mock boundary once: mock what crosses the process (network, filesystem, clock, randomness) and keep pure logic real, so tests fail for the right reasons. Map the chosen mocking approach to the framework's idiom and show how a dependency gets injected or patched.

Set the coverage target per function rather than a single number, weighting error handling and data processing higher. Then write one complete test per critical function in the framework's style, with arrange, act, and assert visible and the mock set up the way the guidelines say. Name the tests so a failure reads as a sentence.

### Output
Return a markdown document with four sections: Overview (approach and mock boundary), Test Plan Table (function, test case, mock needed, target coverage), Sample Test Code (one full test per critical function in fenced blocks), and Mock Guidelines (what to mock, what to keep real, how).

## Pitfalls

- Mocking the module's own pure functions, so tests pass while the real logic is never executed.
- Planning one test per function instead of one per behaviour, which hits the coverage number and misses the error branches.
- Choosing a mock library idiom the framework does not support, such as patching in Go where injection is the only route.
