Use when adding new error messages to React, or seeing "unknown error code" warnings.
npx skills add 4meta5/skills --skill "unit-test-workflow"
Install specific skill from multi-skill repository
# Description
Guided multi-phase workflow for designing and generating comprehensive unit tests
# SKILL.md
name: unit-test-workflow
description: Guided multi-phase workflow for designing and generating comprehensive unit tests
category: testing
disable-model-invocation: false
user-invocable: true
allowed-tools: Read, Grep, Glob, Bash, Write, Edit
Unit Test Generation Workflow
Generate unit tests for given function(s) in a codebase. Work in phases. Output only the requested artifacts.
Inputs Required
- fileOrFolder: The file or folder path to generate unit tests for
- functionToTest (optional): Specific function to test
- language (optional): Override language detection
Procedure
Phase 1 - Detect Language and Environment
- Identify programming language from file extension
- Detect testing framework used in the codebase by analyzing dependencies file and existing test files
- If multiple frameworks detected, choose the one used for unit tests. Prefer the one already present in existing tests file close to fileOrFolder location
Phase 2 - Locate Placement
- Search for existing tests covering the target module. Decide if test should be appended to existing file or if new file should be created
- If creating new file, analyze existing test files to correctly use same naming convention
- If appending, set up test cases similarly to existing tests. If creating new file, analyze existing test files to correctly set up the testing framework
Phase 3 - Analyze Code Under Test
- Parse signatures, inputs, outputs, side effects, expected and exceptional paths, async/await, throw or reverts, edge cases
- Map branches and guards. Identify boundary values and invariants. Mark non-determinism sources (time, RNG, I/O)
Phase 4 - Design Cases
- Create a minimal set for branch coverage. Include happy paths, boundary/edge cases, and failure modes
- Add security-focused cases: invalid/tainted inputs, injection payloads, path traversal, overflow/underflow, encoding pitfalls, fuzz/property checks for pure functions
- Define mocking/stubbing plan attempting to follow existing patterns to never hit real network, database, filesystem, clock, or randomness
Phase 5 - Emit Tests
- Produce tests consistent with the framework's style and project imports. Keep small, pure helpers. No hidden side effects
- Add as many tests as seem appropriate to cover all path/security/cases/edge cases
- Ensure deterministic execution
Phase 6 - Validate Statically
- Self-check imports, assertion usage, compilation or type errors and lints. Avoid duplicate tests
- Output estimated coverage from new tests
Phase 7 - Run Tests
- Run tests individually following test framework instructions and make sure they pass
Language Specifics
- TypeScript/JavaScript: Respect tsconfig/moduleResolution. Detect framework in package.json. Use fake timers instead of real time
- Rust: Use #[cfg(test)] modules, proptest when property tests enabled
Constraints
- No original code file writes or schema changes
- Use meaningful test case names
- Prefer pure helpers and table-driven tests
- Analyze only within the given code. Do not invent missing context or external APIs
Skill Chaining
After Phase 7 (Run Tests)
| Chain To | Condition |
|---|---|
| property-based-testing | Pure functions, roundtrip patterns detected |
| repo-hygiene | Always (terminal) |
Chains From
| Source | When |
|---|---|
| suggest-tests | HIGH risk functions identified |
| tdd | Comprehensive generation needed |
Testing Pipeline Position
unit-test-workflow is step 3 in the testing pipeline:
tdd → suggest-tests → unit-test-workflow → property-based-testing → repo-hygiene
↑
(you are here)
Terminal Chain
After all tests pass: repo-hygiene (clean temporary test files)
# Supported AI Coding Agents
This skill is compatible with the SKILL.md standard and works with all major AI coding agents:
Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.