unit-testing

Write regression-focused unit tests with disciplined mocking and scenario-based naming.

Updated Sep 14, 2026
One-click install
npx skills add https://github.com/Royrahav/my_claude_components --skill unit-testing-royrahav
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: unit-testing
Source: https://github.com/Royrahav/my_claude_components/tree/main/skills/unit-testing
Command: npx skills add https://github.com/Royrahav/my_claude_components --skill unit-testing-royrahav

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Test suites often give false confidence: tests that assert nothing meaningful, over-mocked tests that mirror the implementation, and coverage numbers chased as goals. This Skill guides writing unit tests that actually catch regressions and pin down intended behavior. ## Core Features & Use Cases - Regression-guard workflow: Reproduce a bug in a failing test first, fix the code, then confirm the test passes and keep it permanently. - Mocking discipline: Apply the dummy/stub/fake/spy/mock taxonomy correctly, fake at architectural boundaries, and avoid over-mocking cheap in-process collaborators. - Test structure and naming: Use Arrange-Act-Assert structure, one behavior per test, and scenario-based names that explain failures without opening the file. - Coverage judgment: Treat coverage as a diagnostic for gaps in business logic, not a target, and know what is not worth testing (getters, generated code, pass-through wrappers). - Use Case: After fixing a coupon threshold bug, write the failing boundary test first, apply the one-character fix, and add neighboring boundary tests so the off-by-one can never silently return. ## Quick Start Write unit tests for this function following the regression-prevention guidelines, with scenario-based names and minimal mocking.

Frequently Asked Questions about unit-testing

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a regression test for a bug fix?

Write a failing test that reproduces the bug before touching the fix, asserting the correct behavior. Confirm it fails for the expected reason, apply the fix, verify it passes, and keep the test permanently as a regression guard.

What is the difference between a mock, stub, fake, and spy?

A stub returns canned answers, a fake is a working simplified implementation like an in-memory repository, a spy records how it was called, and a mock has pre-programmed expectations about interactions. Prefer fakes over mocks whenever the dependency is cheap to implement in-memory.

When should I mock a dependency in unit tests?

Mock or fake only at architectural boundaries: network calls, databases, filesystem, wall-clock time, randomness, and third-party SDKs. Do not mock cheap in-process collaborators, since over-mocking turns tests into implementation mirrors that pass even when logic is wrong.

What code is not worth unit testing?

Skip trivial getters, framework wiring, generated code, pure configuration, thin pass-through wrappers, and third-party library internals. Focus testing effort on business logic, state transitions, boundary conditions, error handling, and anything that has caused a production bug.

Why do my tests pass even when the logic is broken?

This usually means tests assert trivial conditions or mock away the exact behavior they claim to verify. Assert on observable outcomes like return values and saved state rather than call shapes, and exercise real collaborators where they are cheap and deterministic.

Should I aim for 100% test coverage?

No. Coverage measures which lines executed, not whether assertions verify correct behavior. Use coverage reports as a diagnostic to find untested business-critical branches, not as a target, since high coverage with weak assertions still ships regressions.