writing-tests
БесплатноБез исполняемых скриптовНе проверенGates whether a new test should exist and keeps it cheap and honest, protecting CI from tests that guard nothing. Use before any change to what a pytest…
от PostHog★ 41 278 звёзд на GitHubОб этом скилле
Writing tests worth keeping
The handbook carries the rationale and the same rules for people: Backend coding conventions › Testing (docs/published/handbook/engineering/conventions/backend-coding.md).
This skill is the gate an agent runs before it writes a test.
It holds the decision procedure and a catalog of the bug shapes we actually ship.
The gate covers added coverage, not only new test functions.
One fixture and one assertion added to an existing block go through the same questions, because that is the shape this skill prefers.
The gate
Answer questions 1 and 2 in one sentence each before you write the test, and question 3 before you commit it. A question you can't answer stops the test.
1. Does it earn its place?
What realistic regression does this test catch that no existing test already catches?
Name the bug, the code path, and the input that would break it.
"Increases coverage", "good practice", and "the function exists" are not answers.
A good answer sounds like "if someone makes parse_filters drop the team_id clause, this fails" or "empty-cohort input used to 500; this locks in the 400."
Aim each test at a failure mode we actually ship. references/mistakes-we-make.md catalogs those shapes, the test that catches each, and the failure modes no unit test should chase. A test that maps to none of them is probably not worth keeping.
2. Where does it go?
Passing question 1 buys the coverage, not a new test function. Find the test that covers the nearest behavior and answer:
Why can't this be a case in that test?
When your case is a variation of that behavior, extend it with a @parameterized case in Python or a test.each row in Jest.
Write a standalone test only when you can name one of three reasons: the setup differs, the behavior belongs to a different unit, or no relevant test exists.
"It's cleaner as its own test" names none of them.
Extend to remove duplication.
A parameterized case is still its own invocation, so setUp and beforeEach run for it as they would for a standalone function, and extending saves no setup time.
Fold in variations of the same behavior, and give assertions about other behavior their own test.
Extending adds your case, not the neighbor's habits. When the nearest test mocks internal helpers or asserts on mock calls, give your case real input through the public interface and assert an outcome. When that test's harness can't observe the outcome, the setup differs, so write a standalone test.
Search for the nearest test first; question 2 has no answer without it.
A new test file needs a team owner, because ownership routes its failures and flakes.
Put it next to the code it tests, inside products/<name>/ when one product owns the behavior, so it inherits that owner.
Check with hogli owners:who <path>.
When no team owns the path, name the team responsible for the behavior it checks in the nearest owners.yaml, not the team of a helper it imports.
CI fails a pull request that leaves a test file with no team owner: a new file, a moved file, or a file that an owners.yaml edit left without a team.
The pre-push hook runs the same check and blocks the push.
3. Does it go red?
Break the line the test guards: drop the clause, flip the condition, or return early. Run the test, and watch it fail for the reason you named in question 1. Then restore the line. For a bug fix, the pre-fix code is the broken line.
A test that stays green guards nothing. Rewrite it to assert an outcome, or delete it. This check catches tautologies and mock plumbing on every level, so run it on each test you add or change.
Tests that guard nothing
Most low-value tests take one of these shapes. Recognize them and skip them.
Framework behavior. Getters, setters, constants, dataclass field assignment, that Django saved a row, that DRF serialized a field, or that a library does what its docs say. That tests someone else's code.
Change-detector tests. A test that mirrors the implementation by asserting which private methods ran, in what order, with mocks wired to match the current code. It fails on every refactor and catches no real bug. Assert an outcome instead. See Change-Detector Tests Considered Harmful and Prefer Testing Public APIs.
Redundant coverage. Ten tests that run the same path with different data are one parameterized test. AI-generated suites bloat here first, turning a 30-second suite into 3 minutes with hundreds of near-identical cases.
Coverage-chasing. An uncovered line is information, not a
Установить writing-tests в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл writing-tests?
Gates whether a new test should exist and keeps it cheap and honest, protecting CI from tests that guard nothing. Use before any change to what a pytest, Jest, or Playwright test asserts or sets up, down to one fixture or one assertion added to an existing block. Carries the value bar (every test catches a realistic regression no existing test catches; extend the nearest test with your case, not its mocks; drive input through the public interface and assert an outcome a caller observes; parameterize near-duplicates; break the guarded line and watch the test go red) and the cost bar (the lowest level of the cost ladder where the behavior exists; a real dependency only when the behavior uses it; stubs only at true boundaries; Django TestCase over TransactionTestCase; no sleeps; no time bombs from unpinned dates). For an existing flaky test use `/fixing-flaky-tests`; once this gate says a Playwright test is warranted, use `/playwright-test` for mechanics.
Как установить скилл writing-tests?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл writing-tests запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
doc-coauthoring
Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision…
от Anthropicacademy-guide
Stop 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…
от Anthropicinternal-comms
A 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…
от Anthropicskill-development
This 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…
от Anthropic