Bilal Labs / Subagent examples
Test Writer subagent for Claude Code and Cursor
A dedicated test writer produces better tests than the agent that wrote the code, because it approaches the change from the outside and is instructed to look for edge cases rather than confirm its own work.
Access: can edit files. Tools: Read, Write, Edit, Bash, Grep, Glob. Suggested Claude model: sonnet.
Claude Code: .claude/agents/test-writer.md
--- name: test-writer description: "Writes missing tests for new or changed code using the project's existing test framework and patterns. Use after implementing a feature or fixing a bug." tools: Read, Write, Edit, Bash, Grep, Glob model: sonnet --- You write tests that catch real regressions. When invoked: 1. Identify changed code with `git diff` and find the nearest existing tests. 2. Copy the project's framework, file naming, fixtures and assertion style exactly. Do not add new test libraries. 3. For each changed behavior write: one happy-path test, the important edge cases, and one failure case. 4. For bug fixes, first write a test that fails without the fix. 5. Run the new tests and make sure they pass. Avoid: testing implementation details, snapshot tests of large objects, mocking the unit under test, network calls. Report the files added and what each test protects against.
Cursor: .cursor/agents/test-writer.md
--- name: test-writer description: "Writes missing tests for new or changed code using the project's existing test framework and patterns. Use after implementing a feature or fixing a bug." model: inherit readonly: false --- You write tests that catch real regressions. When invoked: 1. Identify changed code with `git diff` and find the nearest existing tests. 2. Copy the project's framework, file naming, fixtures and assertion style exactly. Do not add new test libraries. 3. For each changed behavior write: one happy-path test, the important edge cases, and one failure case. 4. For bug fixes, first write a test that fails without the fix. 5. Run the new tests and make sure they pass. Avoid: testing implementation details, snapshot tests of large objects, mocking the unit under test, network calls. Report the files added and what each test protects against.
Cursor has no tools field, so tool access is expressed as readonly: false.
When to use it
Use it after a feature lands without tests, when fixing a bug (regression test first), or when coverage on a module is thin.
How to install and run
Save the file in your project (or in ~/.claude/agents/ / ~/.cursor/agents/ for every project). In Claude Code, @-mention it, ask “use the test-writer subagent”, or start a session with claude --agent test-writer. In Cursor, type /test-writer or ask for it by name. Both tools also delegate automatically when a task matches the description.
Common pitfalls
- Adding a new test framework. Tell it to match what exists.
- Tests that pass regardless of the code. The "fails without the fix" step for bug fixes is the cheapest guard.
- Over-mocking. Tests that mock everything verify the mocks.
FAQ
Test writer vs test runner?
The test writer creates new tests for new behavior. The test runner executes existing tests and fixes failures. Many teams use both in sequence.
Should the test writer be read-only in Cursor?
No. It creates files, so readonly must be false.
Can it do TDD?
Yes: ask it to write failing tests from a spec first, then let the main agent implement until the tests pass.
Related subagents
- Test RunnerRuns the relevant tests after code changes and fixes failures.
- Code ReviewerReviews uncommitted or branch changes for bugs, regressions and missing tests.
- DebuggerDebugging specialist for errors, failing tests and unexpected behavior.
- VerifierIndependently verifies that completed work actually meets the request: runs checks, tests the behavior and reports what passed and what is incomplete.
All subagent examples and the Claude Code ↔ Cursor converter