writing-tests

Guides writing behavior-focused tests with a mandatory watch-it-fail verification gate.

Updated Aug 3, 2026
Ready to run
npx skills add https://github.com/m-de-graaff/skills --skill writing-tests-m-de-graaff
💬 Prompt for ChatGPT / Claude Chat▼
Please help me install this Agent Skill.
Skill: writing-tests
Source: https://github.com/m-de-graaff/skills/tree/main/skills/writing-tests
Command: npx skills add https://github.com/m-de-graaff/skills --skill writing-tests-m-de-graaff

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Tests that were never observed failing often assert nothing, and brittle, flaky, or coverage-driven test suites erode trust instead of building it. This Skill enforces a disciplined approach to writing tests that actually detect regressions. ## Core Features & Use Cases - Red Gate Enforcement: Requires every test to be watched failing before it is trusted, whether for new features, existing code, or bug regression tests. - Behavior-Focused Guidance: Directs testing at observable boundaries (inputs, outputs, errors) rather than implementation details, with rules for naming, arrange-act-assert structure, factories over shared fixtures, and boundary mocking. - Brittleness and Flake Remediation: Provides tables of brittle patterns and fixes, and treats intermittent failures as race-condition bug reports rather than nuisances to retry. - Use Case: When fixing a production bug, use this Skill to write a regression test, watch it fail against the buggy code, then verify it passes after the fix. ## Quick Start Ask the AI to write a regression test for a bug and watch it fail before applying the fix.

Frequently Asked Questions about writing-tests

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

FAQPage Schema
How do I write a test that actually catches bugs?▼

Watch the test fail before trusting it: write it first for new code, or break existing code and confirm the test goes red. A test never observed failing may assert nothing due to a typo'd selector or a mock that always returns the expected value.

What should I test and what should I skip?▼

Test observable behavior at the unit boundary: return values, side effects, and error types. Skip framework internals, constants, generated code, and trivial getters, since those tests cost runtime without detecting anything.

How do I fix a flaky test that fails intermittently?▼

Treat intermittent failure as a race-condition bug report, not a nuisance. Never add retries, sleeps, or bigger timeouts; instead wait on conditions rather than durations and check for shared state between tests. If unfixable now, quarantine it explicitly with a ticket.

Should I use shared fixtures or factories for test data?▼

Use a factory function that accepts overrides, so each test states the fields it depends on and inherits sane defaults for the rest. Shared fixtures hide preconditions, and a later edit for another test can silently break yours.

Is high code coverage a good target for a test suite?▼

Coverage is a diagnostic, not a target. A percentage goal incentivizes tests that execute lines without asserting behavior; 100% line coverage with a trivial assertion is 0% behavior coverage. Act on uncovered branches instead.

When should I mock in unit tests?▼

Mock only at process boundaries: network, clock, filesystem, randomness, and third-party SDKs. Mocking your own service layer lets tests pass when components disagree, and excessive mock setup signals the unit has too many collaborators.