skills/generate-unit-tests/SKILL.md
Generates unit tests for already-implemented features by reading deferred test notes from the task list and analyzing source code. Use after the build phase when tasks in specs/tasks/todo.md have an unchecked "Tests written" checkbox. Use when running /test to execute the test phase.
npx skillsauth add SystangoTechnologies/agent-skills generate-unit-testsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Read the deferred test notes written during planning, analyze the corresponding source code, write comprehensive tests, and verify they pass. This skill executes the test phase that the build phase explicitly skips — converting **Unit Tests (deferred):** sections in specs/tasks/todo.md into real, passing test files covering happy paths, edge cases, and error conditions.
/build on one or more tasksspecs/tasks/todo.md has an unchecked - [ ] Tests written checkboxWhen NOT to use: During the build phase — that separation is intentional. Do not mix test writing with feature implementation.
┌──────────────────────────────────────────────────────┐
│ │
│ Read task's Unit Tests (deferred) section ──→ │
│ Analyze source files listed in task ──→ │
│ Select framework + load testing patterns ──→ │
│ Generate: happy path + edge cases + ──→ │
│ error conditions + setup/teardown │
│ Run npm test ──→ All pass? ──→ │
│ Check [x] Tests written in todo.md ──→ │
│ Next task │
│ │
│ (After ALL tasks done) │
│ Commit all test files once │
│ │
└──────────────────────────────────────────────────────┘
Before writing any tests, check:
specs/tasks/todo.md are marked [x] (outer task checkbox)Unit Tests (deferred) checkbox is already checked [x] (would indicate tests were written during build — a violation)npm run build or equivalent build command succeedsIf you find test files already created during the build phase: Flag this to the user as a process violation. The build phase must not create test files — that is the test phase's responsibility.
Open specs/tasks/todo.md. Find tasks where the Unit Tests (deferred) section has an unchecked Tests written checkbox:
**Unit Tests (deferred):**
- [ ] Tests written ← unchecked = needs tests
- Functions/behaviors to cover: createTask, validateInput
- Edge cases: empty title, duplicate ID
- Test type: unit
- Suggested file: `tests/services/task-service.test.ts`
Process tasks in top-to-bottom order. Skip tasks where - [x] Tests written is already checked.
Before writing any test, read the source files listed in the task's "Files likely touched". Understand:
This analysis — not just the deferred notes — determines what tests to write.
Choose the test framework based on the project's existing setup:
| Language / stack | Framework |
|---|---|
| TypeScript / JavaScript (Node) | Jest or Vitest (check package.json) |
| React components | Jest + React Testing Library |
| Python | pytest or unittest |
| Java / Kotlin | JUnit or TestNG |
| Go | Go testing package |
| Ruby | RSpec or Minitest |
Load references/testing-patterns.md for the appropriate patterns (Arrange-Act-Assert, mocking, React Testing Library, Supertest, Playwright).
Use the suggested file path from the task. If the file already exists, add to it rather than replacing.
Every test suite must cover:
Test structure rules:
[unit] [expected behavior] [condition]Mocking rules:
// Good: mocks only the DB boundary
jest.mock('./db', () => ({
tasks: { insert: jest.fn().mockResolvedValue({ id: '1' }) }
}));
// Bad: mocks an internal helper
jest.mock('./utils/validate', () => ({ validateTitle: jest.fn() }));
Import and scaffold:
Emit complete test files with:
describe blocks grouping related testsbeforeEach / afterEach for setup and teardownit / test blocks using Arrange-Act-Assertnpm test
All tests must pass before proceeding. If a test fails:
Tests written until all tests are greenAfter tests pass, update the task in specs/tasks/todo.md:
**Unit Tests (deferred):**
- [x] Tests written ← check this after tests pass
- Functions/behaviors to cover: createTask, validateInput
...
Do NOT touch the outer task checkbox - [ ] Task N — that belongs to the build phase. Only the Tests written checkbox is yours to check.
Move to the next task with an unchecked Tests written checkbox. Do not commit between tasks.
After all tasks are processed (or at session end):
npm test passes with no failures or skipped tests- [x] Tests written in todo.mdgit-workflow-and-versioning skill to create a single atomic commit| Rationalization | Reality |
|---|---|
| "The deferred section is vague, I'll skip this task" | The notes are a starting point. Read the source code — it tells you everything the tests need to cover. |
| "The implementation is simple, tests aren't needed" | Simple functions are the easiest to test and the most often broken by adjacent changes. Write the tests. |
| "I'll run all tests at the end" | Run npm test after each task. A failure caught per-task is a 2-minute fix; caught at the end, it's a debugging session. |
| "The build phase verified the feature works" | Build verification checks compilation only. Tests check behavior. They are not the same thing. |
| "I found a bug — I'll fix the source code quickly" | Note it and surface it. Fixing source during the test phase mixes concerns and can introduce new failures. |
| "I should write the test first (TDD-style)" | This skill is post-implementation by design. The deferred section already captured the intent — your job is to generate tests that verify the existing code against that intent. |
[x] Tests written before npm test passesdescribe block with no groupingAfter all tasks in the session are done:
npm test passes with zero failures and zero skipped tests- [x] Tests written in todo.mdtools
Creates specs before coding with mandatory Jira MCP validation and story-key grounding. Use when starting a Jira-tracked feature or significant change and requirements are unclear, ambiguous, or incomplete.
devops
Prepares production launches and updates Jira ticket/task comments. Use when preparing to deploy to production and when launch readiness/progress must be communicated in Jira.
tools
Breaks Jira story work into ordered tasks. Use when you have a story spec and need to break work into implementable tasks with story-scoped files under `jira-spec/{story-id}/`. Use when a task feels too large to start, when you need to estimate scope, or when parallel work is possible.
development
Discovers and invokes agent skills. Use when starting a session or when you need to discover which skill applies to the current task. This is the meta-skill that governs how all other skills are discovered and invoked.