Build/Update Tests Skill
Evaluate test coverage and create or update tests when gaps or pattern violations are identified.
When to Use
Invoke when user says:
- "build tests for [file]"
- "update tests for [file]"
- "test [component/service/hook]"
- "add test coverage for [file]"
- "check test coverage"
| Phase |
Action |
Reference |
| 1 |
Code Analysis & Risk Assessment |
execution-phases.md |
| 2 |
Existing Test Discovery & Pattern Compliance |
execution-phases.md |
| 3 |
Test Design |
execution-phases.md |
| 4 |
Test Implementation |
execution-phases.md |
| 5 |
Validation |
execution-phases.md |
| 6 |
Reporting |
report-template.md |
For detailed phase instructions: references/execution-phases.md
Risk Matrix
| Risk Level |
Characteristics |
Required Tests |
| High |
Business logic, mutations, forms, auth, payments |
Unit + Integration + E2E |
| Medium |
Data fetching, filtering, validation, hooks |
Unit + Integration OR Unit + E2E |
| Low |
Pure utilities, formatters, type guards |
Unit only |
Code Type Requirements
| Code Type |
Required Tests |
| User-facing component |
Unit + E2E |
| Form component |
Unit + E2E |
| Service with mutations |
Unit + Integration + E2E |
| Service read-only (simple) |
Unit |
| Service read-only (complex) |
Unit + Integration |
| Pure utility |
Unit |
| React hook (simple) |
Unit |
| React hook (complex) |
Unit + Integration |
| Page component |
E2E |
Test File Locations
| Level |
Pattern |
Example |
| Unit |
src/**/__tests__/[name].test.{ts,tsx} |
src/components/__tests__/SessionForm.test.tsx |
| Integration |
src/**/*.integration.test.{ts,tsx} |
src/services/__tests__/email.integration.test.ts |
| E2E |
playwright/tests/*.spec.ts |
playwright/tests/session-creation.spec.ts |
Pattern Compliance
Check these pattern documents before writing tests:
claude-patterns/testing-patterns.md (React component unit tests)
claude-patterns/vitest-testing-patterns.md (Service/utility unit tests)
claude-patterns/playwright-best-practices.md (E2E tests)
Priority Order
| Priority |
Type |
Examples |
| P0 (Must Fix) |
Safety & Correctness |
No direct DB inserts in E2E, proper async handling, worker validation |
| P1 (Should Fix) |
Maintainability |
test.step() usage, proper cleanup, comprehensive assertions |
| P2 (Nice to Have) |
Best Practices |
Naming conventions, organization, comments |
Fix P0 violations before creating new tests—a test that violates patterns is worse than no test.
For detailed patterns: references/best-practices.md
Basic:
Use build-update-tests skill for src/components/MyComponent.tsx
With requirements:
Use build-update-tests for src/services/email.service.ts with critical flows from docs/email-requirements.md
# Run unit tests for specific file
npm run test:unit -- [test-file-name]
# Run all unit tests
npm run test:unit
# Run E2E tests
npx playwright test [spec-file]
Produce a comprehensive report using references/report-template.md:
- Evaluation Phase: Risk assessment, test discovery, pattern compliance, gap analysis
- Implementation Phase: Actions taken, tests created/updated, coverage achieved
- Summary: Strengths, warnings, gaps fixed, recommendations
Approval Gates
| Gate |
Phase |
Question |
| None |
- |
This skill runs autonomously without user approval gates |
Note: Test creation is non-destructive. User reviews output report and decides what to keep.
Safety Rules
- Never delete existing passing tests - only add or update
- Fix P0 pattern violations before creating new tests - bad tests are worse than no tests
- Preserve existing test structure - don't reorganize without clear benefit
- Cannot create E2E tests without understanding full user workflow
- Cannot determine test priority without requirements documentation
- Complex mocking may require code refactoring for testability
Quick Reference
# Find existing tests
glob "src/**/__tests__/**/*.test.{ts,tsx}"
glob "playwright/tests/*.spec.ts"
# Check for pattern docs
cat claude-patterns/testing-patterns.md
cat claude-patterns/playwright-best-practices.md
- references/execution-phases.md - Detailed 6-phase workflow
- references/report-template.md - Output report format
- references/best-practices.md - Testing patterns and examples
Version History
v3.2.0 (2025-01-18): AI optimization updates
- Add blockquote summary after title
- Soften directive language per Opus 4.5 guidance
v3.1.0 (2025-12-28): Added missing sections per skill-authoring-patterns audit
- Added trigger phrases to frontmatter description
- Added
<approval_gates> section
- Added
<safety_rules> section
- Added
<references> section
v3.0.0 (2025-12-28): Refactored to follow skill-authoring-patterns
- Reduced from 850 to ~180 lines
- Created references/: execution-phases.md, report-template.md, best-practices.md
- Added XML tags for structure
- Converted to imperative writing style
v2.0.0 (2025-11-15): Combined audit and implementation workflows
v1.0.0 (2025-10-01): Initial release
1---2name: build-update-tests3description: Evaluate existing test coverage, identify gaps and pattern violations, then create or update comprehensive tests. Use when user says "build tests", "update tests", "test [component]", "add test coverage", or "check test coverage".4---56# Build/Update Tests Skill78> Evaluate test coverage and create or update tests when gaps or pattern violations are identified.910<when_to_use>1112## When to Use1314Invoke when user says:1516- "build tests for [file]"17- "update tests for [file]"18- "test [component/service/hook]"19- "add test coverage for [file]"20- "check test coverage"21 </when_to_use>2223<workflow>24## Workflow Overview2526| Phase | Action | Reference |27| ----- | -------------------------------------------- | ------------------------------------------------------------- |28| 1 | Code Analysis & Risk Assessment | [execution-phases.md](references/execution-phases.md#phase-1) |29| 2 | Existing Test Discovery & Pattern Compliance | [execution-phases.md](references/execution-phases.md#phase-2) |30| 3 | Test Design | [execution-phases.md](references/execution-phases.md#phase-3) |31| 4 | Test Implementation | [execution-phases.md](references/execution-phases.md#phase-4) |32| 5 | Validation | [execution-phases.md](references/execution-phases.md#phase-5) |33| 6 | Reporting | [report-template.md](references/report-template.md) |3435For detailed phase instructions: [references/execution-phases.md](references/execution-phases.md)36</workflow>3738<risk_matrix>3940## Risk Matrix4142| Risk Level | Characteristics | Required Tests |43| ---------- | ------------------------------------------------ | -------------------------------- |44| **High** | Business logic, mutations, forms, auth, payments | Unit + Integration + E2E |45| **Medium** | Data fetching, filtering, validation, hooks | Unit + Integration OR Unit + E2E |46| **Low** | Pure utilities, formatters, type guards | Unit only |4748### Code Type Requirements4950| Code Type | Required Tests |51| --------------------------- | ------------------------ |52| User-facing component | Unit + E2E |53| Form component | Unit + E2E |54| Service with mutations | Unit + Integration + E2E |55| Service read-only (simple) | Unit |56| Service read-only (complex) | Unit + Integration |57| Pure utility | Unit |58| React hook (simple) | Unit |59| React hook (complex) | Unit + Integration |60| Page component | E2E |6162</risk_matrix>6364<test_locations>6566## Test File Locations6768| Level | Pattern | Example |69| ----------- | --------------------------------------- | -------------------------------------------------- |70| Unit | `src/**/__tests__/[name].test.{ts,tsx}` | `src/components/__tests__/SessionForm.test.tsx` |71| Integration | `src/**/*.integration.test.{ts,tsx}` | `src/services/__tests__/email.integration.test.ts` |72| E2E | `playwright/tests/*.spec.ts` | `playwright/tests/session-creation.spec.ts` |7374</test_locations>7576<pattern_compliance>7778## Pattern Compliance7980Check these pattern documents before writing tests:8182- `claude-patterns/testing-patterns.md` (React component unit tests)83- `claude-patterns/vitest-testing-patterns.md` (Service/utility unit tests)84- `claude-patterns/playwright-best-practices.md` (E2E tests)8586### Priority Order8788| Priority | Type | Examples |89| ----------------- | -------------------- | --------------------------------------------------------------------- |90| P0 (Must Fix) | Safety & Correctness | No direct DB inserts in E2E, proper async handling, worker validation |91| P1 (Should Fix) | Maintainability | test.step() usage, proper cleanup, comprehensive assertions |92| P2 (Nice to Have) | Best Practices | Naming conventions, organization, comments |9394Fix P0 violations before creating new tests—a test that violates patterns is worse than no test.9596For detailed patterns: [references/best-practices.md](references/best-practices.md)97</pattern_compliance>9899<invocation>100## Invocation101102Basic:103104```105Use build-update-tests skill for src/components/MyComponent.tsx106```107108With requirements:109110```111Use build-update-tests for src/services/email.service.ts with critical flows from docs/email-requirements.md112```113114</invocation>115116<commands>117## Commands118119```bash120# Run unit tests for specific file121npm run test:unit -- [test-file-name]122123# Run all unit tests124npm run test:unit125126# Run E2E tests127npx playwright test [spec-file]128```129130</commands>131132<output>133## Output134135Produce a comprehensive report using [references/report-template.md](references/report-template.md):1361371. **Evaluation Phase**: Risk assessment, test discovery, pattern compliance, gap analysis1382. **Implementation Phase**: Actions taken, tests created/updated, coverage achieved1393. **Summary**: Strengths, warnings, gaps fixed, recommendations140 </output>141142<approval_gates>143144## Approval Gates145146| Gate | Phase | Question |147| ---- | ----- | -------------------------------------------------------- |148| None | - | This skill runs autonomously without user approval gates |149150Note: Test creation is non-destructive. User reviews output report and decides what to keep.151</approval_gates>152153<safety_rules>154155## Safety Rules1561571. **Never delete existing passing tests** - only add or update1582. **Fix P0 pattern violations before creating new tests** - bad tests are worse than no tests1593. **Preserve existing test structure** - don't reorganize without clear benefit160 </safety_rules>161162<limitations>163## Limitations164165- Cannot create E2E tests without understanding full user workflow166- Cannot determine test priority without requirements documentation167- Complex mocking may require code refactoring for testability168 </limitations>169170<quick_reference>171172## Quick Reference173174```bash175# Find existing tests176glob "src/**/__tests__/**/*.test.{ts,tsx}"177glob "playwright/tests/*.spec.ts"178179# Check for pattern docs180cat claude-patterns/testing-patterns.md181cat claude-patterns/playwright-best-practices.md182```183184</quick_reference>185186<references>187## References188189- [references/execution-phases.md](references/execution-phases.md) - Detailed 6-phase workflow190- [references/report-template.md](references/report-template.md) - Output report format191- [references/best-practices.md](references/best-practices.md) - Testing patterns and examples192 </references>193194<version_history>195196## Version History197198- **v3.2.0** (2025-01-18): AI optimization updates199 - Add blockquote summary after title200 - Soften directive language per Opus 4.5 guidance201202- **v3.1.0** (2025-12-28): Added missing sections per skill-authoring-patterns audit203 - Added trigger phrases to frontmatter description204 - Added `<approval_gates>` section205 - Added `<safety_rules>` section206 - Added `<references>` section207208- **v3.0.0** (2025-12-28): Refactored to follow skill-authoring-patterns209 - Reduced from 850 to ~180 lines210 - Created references/: execution-phases.md, report-template.md, best-practices.md211 - Added XML tags for structure212 - Converted to imperative writing style213214- **v2.0.0** (2025-11-15): Combined audit and implementation workflows215216- **v1.0.0** (2025-10-01): Initial release217 </version_history>