A comprehensive unit testing skill for AI agents. Focused exclusively on unit tests — one unit in isolation, dependencies mocked. Generates ideal tests and reviews existing ones using best practices from Kent Beck, Martin Fowler, Vladimir Khorikov, and Google.
npx skills add lordprotein/smart-code-test-unitOr via Agent Skills:
npx agent-skills-cli install @lordprotein/smart-code-test-unit- Two Modes — Generate new tests or review existing ones
- Test Scope Selection — Choose which types of tests to generate: business logic, UI components, utilities/hooks
- Code Classification — Extended Khorikov matrix: domain model, UI components, utilities/hooks, trivial, controllers, overcomplicated
- Business Logic Focus — Decision tables, boundary analysis, invariants, state machines
- UI Component Testing — Unit testing individual components in isolation: rendering, interactions, states, a11y, query priority, snapshot rules
- Utility & Hooks Testing — Output-based testing, parameterized tests, boundary value analysis, hooks/composables
- Smart Test Doubles — Classical school by default, mocks only for unmanaged dependencies
- Antipattern Detection — 12 antipatterns with severity levels and fixes
- Language Agnostic — Works with any language and test framework
- Project-Aware — Discovers existing conventions, helpers, and patterns
After installation, run:
/smart-code-test-unit
The skill analyzes your code changes (or specified files) and generates comprehensive unit tests:
- Determines test scope — asks which test types to generate (business logic, UI, utilities)
- Classifies code by testability (domain logic, UI components, utilities, trivial, controllers)
- Identifies test scenarios (happy paths, boundaries, errors, invariants)
- Generates tests following AAA pattern with proper naming
- Self-checks against antipatterns before output
The skill reviews existing tests for quality issues:
- Evaluates against the Four Pillars (Khorikov)
- Detects antipatterns (The Liar, The Mockery, Fragile Tests, etc.)
- Assesses business logic coverage gaps
- Reports findings by severity (P0-P3)
- Asks for confirmation before implementing fixes
- Scope — Determine test types: business logic, UI components, utilities/hooks
- Preflight — Analyze code, detect language/framework, find conventions
- Classify — Extended matrix (domain model / UI component / utility / trivial / controller / overcomplicated)
- Scenarios — Business rules, boundaries, error paths, invariants, UI states, a11y
- Generate — AAA pattern, proper doubles, meaningful names
- Self-check — Verify against antipatterns checklist
- Output — Tests with classification and coverage notes
- Preflight — Collect test files, read production code
- Evaluate — Check against review checklist
- Severity — Assign P0-P3 to each finding
- Output — Findings with suggested fixes
- Confirm — Ask user before implementing changes
| Level | Name | Action |
|---|---|---|
| P0 | Critical | Must fix — false confidence or test pollution |
| P1 | High | Should fix — fragile, over-mocked, missing coverage |
| P2 | Medium | Fix or follow-up — readability, naming, structure |
| P3 | Low | Optional — style, minor suggestions |
smart-code-test-unit/
├── SKILL.md # Main skill definition
├── agents/
│ └── agent.yaml # Agent interface config
└── references/
├── testing-principles.md # Four pillars, FIRST, pyramid, classification
├── test-design-patterns.md # AAA, builders, parameterization, naming
├── test-doubles-guide.md # Dummy/Stub/Spy/Mock/Fake guide
├── business-logic-testing.md # Decision tables, boundaries, invariants
├── ui-component-testing.md # Unit testing UI components, query priority, UI states, a11y, snapshots
├── utility-and-hooks-testing.md # Pure functions, parameterized tests, hooks, boundaries
├── antipatterns-checklist.md # 12 antipatterns with detection and fixes
└── test-review-checklist.md # Structured review checklist
Based on:
- Vladimir Khorikov — Unit Testing: Principles, Practices, and Patterns
- Kent Beck — Test-Driven Development: By Example
- Kent C. Dodds — Testing principles, "Testing Implementation Details", query priority, component testing philosophy
- Martin Fowler — Refactoring, TestDouble, TestPyramid
- Gerard Meszaros — xUnit Test Patterns
- Google — Testing Blog, Software Engineering at Google
- Steve Freeman & Nat Pryce — Growing Object-Oriented Software, Guided by Tests
MIT