Command Palette

Search for a command to run...

Back to skills
skill № 01486

quality-unit-testing

Use when the user asks to write unit tests with mocks, stubs or fakes, test doubles, TDD, the AAA pattern, Jest, Vitest, pytest or JUnit, or meaningful…

FreeNo executable scripts
j4flmaoby j4flmao★ 47 GitHub stars

Install quality-unit-testing in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

About this skill

Unit Testing

Purpose

Write effective unit tests using FIRST principles, AAA pattern, test doubles, and TDD. Ensure test quality, maintainability, and meaningful coverage of business logic. This skill covers test architecture, isolation strategies, mock/stub decisions, CI integration, and test suite health monitoring.

Agent Protocol

Trigger

User mentions unit testing, test doubles, mocking, stubbing, TDD, FIRST principles, code coverage, test structure (AAA), or unit test patterns.

Input Context

  • Modules or functions under test
  • Dependency graph and injection points
  • Existing test suite structure
  • Coverage targets and CI constraints
  • Language and test framework in use

Output Artifact

Unit test suite with proper isolation, test doubles, and CI integration.

Response Format

Test file(s) with:

  1. Proper AAA structure and descriptive naming
  2. Mock/stub/fake definitions at system boundaries
  3. Coverage configuration and CI pipeline integration
  4. Test organization strategy (co-located or centralized)

Completion Criteria

  • All identified functions have unit tests covering happy path, error paths, and edge cases
  • Test doubles used only at system boundaries
  • Tests are fast (< 100ms per test, < 5 min for suite)
  • Coverage meets agreed thresholds (line > 80%, branch > 70%)
  • CI integration configured with coverage reporting and sharding

Workflow

  1. Analyze the unit: Identify the function/module, its dependencies, and its observable behavior (not implementation)
  2. Determine isolation needs: Map dependencies to test double types (mock at boundaries, real for pure functions)
  3. Design test scenarios: List happy path, error paths, edge cases (empty, null, boundary values)
  4. Create test structure: Write describe blocks for organization, it blocks per scenario following AAA/Given-When-Then
  5. Implement mocks: Configure mock responses at dependency boundaries. Use vi.mock/jest.mock for module mocks, vi.spyOn for method spies
  6. Write assertions: Assert observable behavior (return values, state changes, side effects). Avoid asserting internal implementation
  7. Run and verify: Execute tests. Verify coverage meets thresholds. Check test execution time
  8. Refactor tests: Improve test code quality, remove duplication, extract test helpers and factories
  9. Integrate CI: Configure CI with parallel execution, sharding, coverage reporting, and quality gates
  10. Monitor suite health: Track execution time, flakiness, coverage stability. Fix flaky tests immediately

Architecture / Decision Trees

Test Double Selection

Dependency type?
├── External HTTP/network → Mock (MSW/WireMock)
├── Database → Fake (in-memory repo) or Mock at repository boundary
├── File system → Mock (memfs) or in-memory implementation
├── Time (Date, setTimeout) → Fake timers (vi.useFakeTimers)
├── Random/UUID → Stub with fixed values
├── Logger → Stub (no-op or spy)
├── Pure function → Real implementation
└── Internal service → Real implementation or Spy

Framework Selection

Project language?
├── TypeScript/JavaScript
│   ├── New project + ESM → Vitest
│   └── Existing Jest → Jest
├── Java → JUnit 5 + Mockito
├── Python → pytest + pytest-mock
├── Go → testing + testify
├── Rust → cargo test
└── C# → xUnit + Moq/NSubstitute

Common Pitfalls

  1. Over-mocking: Mocking internal details creates brittle tests that break on refactoring. Mock only at module/system boundaries
  2. Testing implementation, not behavior: Tests that assert internal method calls or private state break during refactoring
  3. Shared mutable state across tests: Tests that depend on earlier tests' side effects are unreliable and order-dependent
  4. Slow tests: Tests using real databases, network calls, or filesystem are integration tests, not unit tests
  5. Mocking dependencies you don't own: Mocking third-party library internals creates tight coupling to library details
  6. Empty assertions: Tests without proper assertions (expect(true).toBe(true)) provide false confidence
  7. Brittle string matching: Asserting exact error messages or rendered output makes tests fragile
  8. Granularity mismatch: Testing too large (entire service) or too small (private helpers) a unit
  9. Skipping error paths: Only testing the happy path misses the majority of potential bugs
  10. Coverage chasing: Targeting 100% coverage encourages meaningless tests. Focus on business logic

Best Practices

  1. Follow the AAA pattern (Arrange-Act-Assert) consistently across all tests
  2. Use descriptive test names: "should [expected] when [scenario]"
  3. Mock at system boundaries (network, persistence, time), not implementation internals
  4. Use real implementations for pure functions and value objects
  5. Keep tests fast: mock I/O, use in-memory dependencies, avoid real timers
  6. One assertion concept per test — multiple assertions are fine if they test one behavior
  7. Use factory fun
Full SKILL.md on GitHub

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

Bundled files

  • references/mocking-strategies.md
  • references/tdd-guide.md
  • references/test-doubles.md
  • references/test-organization.md
  • references/test-patterns.md
  • references/unit-testing-advanced.md
  • references/unit-testing-architecture.md
  • references/unit-testing-fundamentals.md
  • references/unit-testing-patterns.md
  • references/unit-testing-workflow-strategies.md

FAQ

What does the quality-unit-testing skill do?

Use when the user asks to write unit tests with mocks, stubs or fakes, test doubles, TDD, the AAA pattern, Jest, Vitest, pytest or JUnit, or meaningful coverage. Produces isolated unit tests and test structure. Not for real database or HTTP tests (use quality-integration-testing) or UI component tests (use frontend-testing).

How do I install the quality-unit-testing skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the quality-unit-testing skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare quality-unit-testing with