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…
от j4flmao★ 47 звёзд на GitHub
Установить quality-unit-testing в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
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:
- Proper AAA structure and descriptive naming
- Mock/stub/fake definitions at system boundaries
- Coverage configuration and CI pipeline integration
- 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
- Analyze the unit: Identify the function/module, its dependencies, and its observable behavior (not implementation)
- Determine isolation needs: Map dependencies to test double types (mock at boundaries, real for pure functions)
- Design test scenarios: List happy path, error paths, edge cases (empty, null, boundary values)
- Create test structure: Write describe blocks for organization, it blocks per scenario following AAA/Given-When-Then
- Implement mocks: Configure mock responses at dependency boundaries. Use vi.mock/jest.mock for module mocks, vi.spyOn for method spies
- Write assertions: Assert observable behavior (return values, state changes, side effects). Avoid asserting internal implementation
- Run and verify: Execute tests. Verify coverage meets thresholds. Check test execution time
- Refactor tests: Improve test code quality, remove duplication, extract test helpers and factories
- Integrate CI: Configure CI with parallel execution, sharding, coverage reporting, and quality gates
- 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
- Over-mocking: Mocking internal details creates brittle tests that break on refactoring. Mock only at module/system boundaries
- Testing implementation, not behavior: Tests that assert internal method calls or private state break during refactoring
- Shared mutable state across tests: Tests that depend on earlier tests' side effects are unreliable and order-dependent
- Slow tests: Tests using real databases, network calls, or filesystem are integration tests, not unit tests
- Mocking dependencies you don't own: Mocking third-party library internals creates tight coupling to library details
- Empty assertions: Tests without proper assertions (expect(true).toBe(true)) provide false confidence
- Brittle string matching: Asserting exact error messages or rendered output makes tests fragile
- Granularity mismatch: Testing too large (entire service) or too small (private helpers) a unit
- Skipping error paths: Only testing the happy path misses the majority of potential bugs
- Coverage chasing: Targeting 100% coverage encourages meaningless tests. Focus on business logic
Best Practices
- Follow the AAA pattern (Arrange-Act-Assert) consistently across all tests
- Use descriptive test names: "should [expected] when [scenario]"
- Mock at system boundaries (network, persistence, time), not implementation internals
- Use real implementations for pure functions and value objects
- Keep tests fast: mock I/O, use in-memory dependencies, avoid real timers
- One assertion concept per test — multiple assertions are fine if they test one behavior
- Use factory fun
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- 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
Что делает скилл 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 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).
Как установить скилл quality-unit-testing?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл quality-unit-testing запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
AnthropicGuide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
academy-guide
AnthropicStop and check this skill before finishing any reply to a question about how to use Claude or a Claude product — it recommends matching courses, tutorials…
internal-comms
AnthropicA set of resources to help me write all kinds of internal communications, using the formats that my company likes to use. Claude should use this skill…
skill-development
AnthropicThis skill should be used when the user wants to "create a skill", "add a skill to plugin", "write a new skill", "improve skill description", "organize skill…