---
name: unit-test-analyzer
description: "Audits a unit test suite against its results and coverage data and returns a prioritised, machine-readable report: what fails, what is flaky, which modules are under-covered, and the fixes to make before release. Use when a unit test run has failures, suspected flaky tests, or coverage below the bar and you need a prioritised report of what to fix before release. Do not use for writing new tests for a function or planning a test suite for an untested module. Related topics: coding, unit."
---

# Unit Test Analyzer

Audits a unit test suite against its results and coverage data and returns a prioritised, machine-readable report: what fails, what is flaky, which modules are under-covered, and the fixes to make before release.

## When to use

Use this skill when a unit test run has failures, suspected flaky tests, or coverage below the bar and you need a prioritised report of what to fix before release. Do not use it for writing new tests for a function or planning a test suite for an untested module.

## 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. Group every failing test by its root cause (fixture, signature change, environment) rather than listing names.
3. Compare coverage per module against the threshold and flag the focus-area modules below it with their uncovered branches.
4. Identify tests that prove nothing: no assertions, mock-only assertions, broad exception catches.
5. When flake detection is on, mark tests whose failures involve timing, ordering, network, or shared state and name the fix for each.
6. Order recommendations by release risk and emit the JSON with every key present, including empty arrays.

## Inputs

- **Project language** (choose one: Python, Java, JavaScript, TypeScript, C#, Go, Ruby)
- **Test framework** (choose one: pytest, JUnit, Jest, Mocha, NUnit, Go test, RSpec)
- **Test results** (longer free text)
- **Coverage report** (longer free text)
- **Coverage threshold in percent** (number from 0 to 100)
- **Recent commit or change** (free text, e.g. "a1b2c3d or the feature just merged")
- **Focus area** (choose any: Business logic, Data access, UI, Performance, Security)
- **Detect flaky tests** (choose one: Yes, No)

## Output

A JSON object with summary, coverage_percent, failing_tests, flaky_tests, and recommendations (target, action, reason) ordered by priority, and nothing outside it.

## Prompt template

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

### Unit Test Analyzer

Review the test suite described below and report what to fix before the next release.

- Project language: {{Project language}}
- Test framework: {{Test framework}}
- Test results: {{Test results}}
- Coverage report: {{Coverage report}}
- Coverage threshold in percent: {{Coverage threshold in percent}}
- Recent commit or change: {{Recent commit or change}}
- Focus area: {{Focus area}}
- Detect flaky tests: {{Detect flaky tests}}

Read the failures first and group them by cause, not by test name: a shared fixture, a changed signature, an environment assumption. Then compare coverage against the threshold per module and flag the ones in the focus area that fall short, naming the uncovered branches when the report shows them. Look for tests that pass without proving anything: no assertions, assertions on mocks only, or broad exception catches. When flake detection is on, mark tests whose failures mention timing, ordering, network, or shared state, and say what would make each deterministic.

Prioritise by release risk: failing tests on changed code first, then untested changed code, then weak tests, then general coverage gaps. Each recommendation names the file or test, the change, and the reason.

### Output
Return a JSON object with keys: summary (a short paragraph), coverage_percent (number), failing_tests (array of test names grouped by cause), flaky_tests (array, empty when detection is off), recommendations (array of objects with target, action, and reason, ordered by priority).

## Pitfalls

- Reporting the overall coverage number when one focus-area module sits at 20 percent behind a healthy average.
- Calling a test flaky because it failed once, without a timing or ordering clue in the failure output.
- Recommending more tests for code that is already covered while the changed code in the commit has none.
