Unit Test Improver
Skill9 starsChanged 8 months agoMITView on GitHub
Reviews existing unit tests for gaps, weak assertions, and missing edge cases, then rewrites them to be more robust.
In this repository61 other files it gives its agents.
- Accessibility Audit HelperSkill
- Agent Context File WriterSkill
- Agent Evaluation Framework BuilderSkill
- AI Feature Spec WriterSkill
- API Documentation GeneratorSkill
- REST API Endpoint DesignerSkill
- Architecture ExplainerSkill
- Article RepurposerSkill
- Auth Flow PlannerSkill
- Blog Outline GeneratorSkill
- Breaking Change DetectorSkill
- Bug Root Cause AnalyzerSkill
- Caching Strategy AdvisorSkill
- Changelog CuratorSkill
- Code Review ChecklistSkill
- Database Schema ReviewerSkill
- Docker Compose GeneratorSkill
- Documentation Gap FinderSkill
- Edge Case DiscoverySkill
- Error Log SummarizerSkill
- FAQ GeneratorSkill
- Flaky Test AnalyzerSkill
- Form UX OptimizerSkill
- Git Commit WriterSkill
- Hallucination Risk ReviewerSkill
- Hybrid Search ArchitectSkill
- Incident Postmortem WriterSkill
- Issue to PR PlannerSkill
- Landing Page Copy ImproverSkill
- LangGraph State Machine DesignerSkill
- LLM Cost OptimizerSkill
- LLM Tracing and Observability SetupSkill
- MCP Integration AssistantSkill
- MCP Server BuilderSkill
- Migration Guide WriterSkill
- Newsletter Summary WriterSkill
- Observability ChecklistSkill
- Playwright Test BuilderSkill
- PR Description WriterSkill
- Prompt Injection Defense AuditorSkill
- Prompt RefinerSkill
- Prompt Version Control WorkflowSkill
- RAG Chunking Strategy AdvisorSkill
- RAG Workflow PlannerSkill
- React Component ReviewerSkill
- README WriterSkill
- Refactor PlannerSkill
- Release Notes GeneratorSkill
- Responsive Layout ReviewerSkill
- SDK Quickstart WriterSkill
- SEO Content OptimizerSkill
- SEO Metadata GeneratorSkill
- Social Post Thread WriterSkill
- Sprint Summary GeneratorSkill
- SQL Query OptimizerSkill
- Stack Trace AnalyzerSkill
- Technical Blog Post WriterSkill
- Tech Debt AuditorSkill
- Troubleshooting Guide BuilderSkill
- Unit Test WriterSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 9 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈9
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 19
Use this before a major refactor (so you can trust the tests will catch regressions), during a code review, or when a bug slips past your …
- Very specific: line 35
Add the instructions below to your .cursorrules or paste them into the Cursor AI pane.
- Distinctive: line 43
When asked to improve unit tests, follow these steps:
- Distinctive: line 47
Read the full test file. Then read the source code being tested.
- Distinctive: line 51
Check every test for these problems:
- Distinctive: line 61
No tests for null/undefined inputs
- Distinctive: line 62
No tests for boundary values (empty array, zero, max value)
- Distinctive: line 63
No tests for the cases identified in the source code's conditional branches
- Very specific: line 73
Test names that don't describe the expected behavior (e.g., it('works'))
- Distinctive: line 211
Always read the source code — tests cannot be properly evaluated without understanding what the code is supposed to do.
- Distinctive: line 212
If the source code itself has bugs, note them separately.
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Unit Test Improver
What this skill does
This skill directs the agent to review an existing set of unit tests and improve them. It looks for weak or incomplete tests — tests that pass even when the code is broken, tests that don't assert the right things, tests that are missing critical edge cases, and tests that test implementation details instead of behavior. The output is an improved, rewritten test suite that is harder to fool and more useful as a safety net.
Use this before a major refactor (so you can trust the tests will catch regressions), during a code review, or when a bug slips past your existing tests.
How to use
Claude Code / Cline
Copy this file to .agents/skills/unit-test-improver/SKILL.md in your project root.
Then ask:
- "Use the Unit Test Improver skill on
tests/cart.test.ts." - "Review and improve the unit tests for
calculateDiscountusing the Unit Test Improver skill."
Provide both the test file and the code being tested.
Cursor
Add the instructions below to your .cursorrules or paste them into the Cursor AI pane. Then share the test file and the source file side by side.
Codex
Paste both the test file (labeled "TESTS") and the source file (labeled "SOURCE") and ask Codex to follow the instructions below.
The Prompt / Instructions for the Agent
When asked to improve unit tests, follow these steps:
Step 1 — Read both the tests and the source
Read the full test file. Then read the source code being tested. Understand what the function is supposed to do before evaluating whether the tests cover it.
Step 2 — Identify test quality issues
Check every test for these problems:
Weak assertions
expect(result).toBeTruthy()instead ofexpect(result).toBe(true)— passes for any truthy valueexpect(result).toBeDefined()when the actual value should be checkedexpect(fn).not.toThrow()without checking the return value- Asserting on the wrong field (e.g., checking
result.idbut notresult.value)
Missing coverage
- The happy path is tested but no error paths
- No tests for null/undefined inputs
- No tests for boundary values (empty array, zero, max value)
- No tests for the cases identified in the source code's conditional branches
Tests that test implementation, not behavior
- Asserting that a specific internal function was called, when what matters is the output
- Asserting on exact internal state that's an implementation detail
- Tests that will break if you rename a private variable
Poor test structure
- Tests with no clear Arrange/Act/Assert structure
- Multiple unrelated assertions in a single test (makes failures hard to diagnose)
- Test names that don't describe the expected behavior (e.g.,
it('works')) - Setup code duplicated across many tests instead of using
beforeEach
Over-mocking
- Mocking the thing being tested, not just its dependencies
- Mocking a dependency and then asserting on the mock instead of the real output
- Tests that pass even if you delete the source code (because everything is mocked)
Step 3 — Identify missing test cases
Using the source code, enumerate every branch, condition, and edge case that should be tested. Cross-reference with the existing tests and list what's missing.
Step 4 — Rewrite the tests
Rewrite the full test file applying these principles:
- Test names should be sentences:
it('returns 0 when the cart is empty')notit('cart test') - One assertion per concept — multiple
.toBe()calls are fine if they're testing the same return value; a single test should not mix unrelated concerns - Use
describeblocks to group tests by function or scenario - Assert on the output, not the internals — if the code produces the right result, the implementation is correct
- Test all branches — every
if,else,catch, andswitchcase should have a test - Use concrete expected values —
expect(total).toBe(29.99)notexpect(total).toBeGreaterThan(0) - Arrange/Act/Assert structure in every test:
// Arrange const cart = [{ price: 10, qty: 3 }]; // Act const total = calculateTotal(cart); // Assert expect(total).toBe(30);
Step 5 — Format the output
First, provide a review summary:
## Test Review Summary
### Issues found
- [List each issue with the test name or line number]
### Missing coverage
- [List each missing case]Then provide the complete rewritten test file.
Example
Input to Agent:
"Use the Unit Test Improver skill.
SOURCE (
discount.ts):export function calculateDiscount(price: number, code: string): number { if (code === 'SAVE10') return price * 0.9; if (code === 'SAVE25') return price * 0.75; if (price > 100) return price * 0.95; return price; }TESTS (
discount.test.ts):it('applies discount', () => { expect(calculateDiscount(50, 'SAVE10')).toBeTruthy(); }); it('works', () => { const result = calculateDiscount(200, ''); expect(result).toBeDefined(); }); ```"
Output from Agent:
Test Review Summary
Issues found
'applies discount': UsestoBeTruthy()— passes for any non-zero number, wouldn't catch a bug returning the wrong discount amount'works': UsestoBeDefined()— passes as long as the function doesn't throw; doesn't verify the correct value- Both test names are vague and don't describe expected behavior
Missing coverage
SAVE25code not tested- Price > 100 with no code not tested
- Invalid/unknown coupon code with price ≤ 100 not tested
- Zero price not tested
- Negative price not tested
import { calculateDiscount } from './discount'; describe('calculateDiscount', () => { describe('with coupon codes', () => { it('applies 10% discount for SAVE10 code', () => { expect(calculateDiscount(100, 'SAVE10')).toBe(90); }); it('applies 25% discount for SAVE25 code', () => { expect(calculateDiscount(100, 'SAVE25')).toBe(75); }); it('coupon codes take priority over price-based discount', () => { expect(calculateDiscount(200, 'SAVE10')).toBe(180); }); }); describe('without coupon codes', () => { it('applies 5% discount when price is above 100', () => { expect(calculateDiscount(200, '')).toBe(190); }); it('applies no discount when price is exactly 100', () => { expect(calculateDiscount(100, '')).toBe(100); }); it('applies no discount when price is below 100', () => { expect(calculateDiscount(50, '')).toBe(50); }); }); describe('edge cases', () => { it('returns 0 for a zero price', () => { expect(calculateDiscount(0, '')).toBe(0); }); it('unknown coupon code falls through to price-based logic', () => { expect(calculateDiscount(200, 'INVALID')).toBe(190); }); }); });
Notes
- Always read the source code — tests cannot be properly evaluated without understanding what the code is supposed to do.
- If the source code itself has bugs, note them separately. Don't write tests that encode the buggy behavior.
- This skill rewrites tests, not source code. If improving the tests reveals a bug, flag it but don't fix it automatically.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

