Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

writing-unit-tests

БесплатноБез исполняемых скриптовНе проверен

Writes and reviews focused, deterministic unit tests that verify behavior through public interfaces instead of implementation details. Use whenever tests are…

jaktestowacот jaktestowac★ 124 звезды на GitHub

Об этом скилле

Writing Unit Tests

Use this skill when the goal is a small, fast test that proves one behavior of one unit. It helps produce tests that read like a specification and survive refactors, instead of tests that mirror the code and break whenever it moves.

This skill is framework-agnostic. It does not assume a runner, an assertion library, or a mocking tool. Detect what the project already uses before writing anything; if nothing exists yet, ask which runner to target and describe the tests in neutral terms until you know.

When to Use

Trigger phrases: "unit tests", "add tests for this", "cover this function", "test coverage", "edge cases", "mock this", "these tests are flaky", "this test breaks on every refactor", "are these tests any good?".

Typical situations:

  • add unit tests for an existing function, class, or module
  • backfill tests for untested legacy code
  • review an existing suite that is brittle, slow, or flaky
  • expand coverage of edge cases and error paths
  • decide what deserves a unit test versus an integration test

Reach for this skill when the code already exists. If the tests should come first and drive the implementation, use test-driven-development instead - then return here for the standard each test it produces must meet.

What a Unit Test Is Here

A unit test exercises one unit of behavior in isolation, with no real I/O.

  • In scope - pure functions, business rules, validators, mappers, reducers, state machines, error handling
  • Out of scope - database queries, HTTP calls, file system access, real timers, cross-module workflows

Pick the narrowest test that gives real confidence

The behavior lives in Test level Why
A calculation, rule, or transformation Unit Fast, exhaustive on edge cases, no setup cost
Collaboration between two owned modules Unit at the outer module's interface Keeps the seam public without mocking internals
A query, schema, or serialization contract Integration Only the real dependency can prove it
The shape of an external provider's responses Contract test Stubs encode an assumption; a contract test is what notices when it rots
A user-visible workflow across layers End-to-end / functional Unit tests cannot observe it

Push edge cases down to the unit level and keep the higher levels thin. If a behavior can only be proven by crossing a process or network boundary, say so and route it to integration coverage rather than forcing it into a unit test with a wall of mocks.

What not to test

Skip these unless they carry real logic:

  • trivial getters, setters, and pass-through wrappers
  • third-party library behavior - test your use of it, not the library itself
  • framework wiring and generated code
  • constants, or anything the type system already guarantees
  • private helpers - they get covered through the public interface that uses them

A test with nothing to prove still costs review time and still breaks on refactors.

Core Rules

  • Test behavior, not implementation - assert on what the public interface returns, throws, or emits. Never reach into private state.
  • One reason to fail - each test proves one behavior. If the name needs "and", split it.
  • Deterministic by construction - inject or freeze time, randomness, IDs, locale, and environment. A test that can fail twice out of a hundred runs is a broken test.
  • Independent and order-free - no shared mutable state between tests, no reliance on execution order, no leaking global setup.
  • Fast - milliseconds, not seconds. Slowness is a signal the unit is not isolated.
  • No logic in the test - no loops, conditionals, or recomputation of the expected value. Expected values are literals from an independent source: the spec, a worked example, a known-good result.
  • Parameterize, don't loop - many similar cases belong in the runner's table-driven or parameterized API, where each row reports as its own test. A hand-rolled for loop hides which case failed.
  • Mock only at real boundaries - substitute things you do not own (clock, network, storage). Mocking internal collaborators couples the test to the design and makes refactoring painful.
  • Prove the test can fail - a test written after the code has never been seen failing. Break the behavior on purpose, watch the test go red, restore, and watch it go green. Evidence, not confidence.
  • Do not reshape production code to make testing easier without saying so - hard-to-test code is a design finding to raise, not something to quietly restructure inside a "just adding tests" change. Ask, then do it as it
Полный SKILL.md на GitHub

Установить writing-unit-tests в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

resources/flaky-test-triage.mdresources/good-and-bad-tests.mdresources/test-doubles-guide.mdresources/unit-test-review-checklist.md

FAQ

Что делает скилл writing-unit-tests?

Writes and reviews focused, deterministic unit tests that verify behavior through public interfaces instead of implementation details. Use whenever tests are added to code that already exists, and when the request mentions unit tests, test coverage, edge cases, mocks or test doubles, "add tests for this function", "cover this module", "these tests are flaky", or "this test breaks every refactor". Also use when reviewing an existing suite for brittleness, weak assertions, or missing boundary cases.

Как установить скилл writing-unit-tests?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл writing-unit-tests запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить writing-unit-tests с