Generic test writing discipline: test quality, real assertions, anti-patterns, and rationalization resistance. Use when writing tests, adding test coverage, or fixing failing tests for any language or framework. Complements language-specific skills.
--- name: ia-writing-tests class: discipline description: >- Generic test writing discipline: test quality, real assertions, anti-patterns, and rationalization resistance. Use when writing tests, adding test coverage, or fixing failing tests for any language or framework. Complements language-specific skills. --- # Writing tests Produce tests that prove the requested behavior and fail when that behavior breaks. Follow user scope and the repository's actual contracts; this skill does not authorize implementation, external actions, or changes to acceptance criteria. ## Procedure 1. Discover the repository's runner, pinned wrapper, configuration, neighboring tests, and CI command before writing tests. Learn both focused and full-suite commands. Use project tooling rather than a global default; keep tracked scripts portable and apply personal wrappers only to the outer invocation. 2. Derive cases from user requirements, implemented behavior, and claims intended for the handoff. Map each acceptance criterion to a discriminating case that a plausible wrong implementation fails. Name tests by observable behavior; keep one behavior per test and make fixtures adversarial on the axis under test. 3. For bug fixes with a reachable test seam, write the reproducer, observe the intended failure, apply the smallest fix, and observe green. If the actual trigger cannot be reached, follow the missing-seam rules in [test-completion.md](./references/test-completion.md). For new features, follow the selected test posture in vertical slices: default to tests-after (one small implementation slice, then its test); with an explicit test-first choice, write one test, then the minimal implementation that passes it. Repeat by slice; writing all tests first and all implementation afterward (horizontal slicing) is an anti-pattern that produces tests for imagined behavior. Refactor after green. Never alter a specification, assertion, fixture, snapshot, or expected output merely to make the implementation pass. 4. Prefer real internal objects, real temporary files, and real test databases. Mock only external boundaries, at the last owned adapter; framework-maintained fakes are appropriate where the framework recommends them. Check the real contract and side effects before mocking. 5. Assert consumer-visible outcomes rather than private structure, mock calls, or framework behavior. Include relevant boundary, invalid-input, concurrency, and failure cases. If error handling catches, logs, substitutes, or rolls back, assert its observable result as well as error visibility. 6. Prove absence/isolation assertions with a run-unique forbidden violation and observe that specific assertion fail. Confirm the control mutation actually landed and its build completed before evaluating it. Remove the control, restore the artifact, and verify green. 7. Run the narrow checks during edits and the applicable complete checks before handoff. Inspect passed/executed counts; an empty or skipped suite is not positive evidence. ## Select the detail needed - When choosing cases, fixture shape, mock boundaries, or unit/integration/E2E balance, read [test-design.md](./references/test-design.md). - For bug reproducers, mutation controls, or assertions that something must not happen, read [regression-proof.md](./references/regression-proof.md). - When reviewing generated tests, changing snapshots, testing async timing, or seeing mocks substitute for behavior, read [test-smells.md](./references/test-smells.md) and the applicable fix ladder in [anti-patterns-extended.md](./references/anti-patterns-extended.md). To audit whether existing tests detect regressions, use ia-test-audit. - For weak aggregates, vacuous assertions, race reproduction, or controls that may never reach their subject, read [oracle-smells.md](./references/oracle-smells.md). It routes to the longer catalogs when those failure shapes apply. - For container state, sandboxing, timeouts, environment relocation, or process/stream isolation, read [isolation-and-sandbox-traps.md](./references/isolation-and-sandbox-traps.md). - For wrappers, filters, conformance oracles, skip conditions, or misleading green summaries, read [false-pass-oracle-traps.md](./references/false-pass-oracle-traps.md). - When byte equivalence or a generated corpus is the contract, read [generated-corpus-techniques.md](./references/generated-corpus-techniques.md); compare against an independent implementation across value shapes and nesting. - When stuck, considering skipping tests, or assembling a test-work handoff, read [test-completion.md](./references/test-completion.md). Before arguing against a needed test, read [rationalization-table.md](./references/rationalization-table.md). ## Verify and report Verify public behavior and edge paths, independence between tests, reviewed expectation changes, and each claimed capability. Mentally remove a guard, flip a branch, or drop a side effect and confirm a test detects it. Prefer a unit suite fast enough for frequent use (under 30 seconds). Report what the tests exercised, actual results, failures, and omissions. Distinguish fixtures from live proof. Use the applicable PHP/Laravel or React/TypeScript skill for framework conventions; this generic skill does not replace them.
don't have the plugin yet? install it then click "run inline in claude" again.
added inputs section documenting test framework, CI setup, and project conventions; made decision logic explicit for bug reproducers, feature slicing, mocking boundaries, and false passes; added output contract specifying test files, counts, assertions, and execution artifacts; added outcome signal defining pass criteria, fixture quality, feedback speed, and coverage transparency.
Produce tests that prove the requested behavior and fail when that behavior breaks. Follow user scope and the repository's actual contracts. this skill does not authorize implementation, external actions, or changes to acceptance criteria.
Write tests that discriminate between correct and broken implementations. use this skill when authoring new tests, expanding test coverage, reproducing bugs, or debugging failing test suites. works across any language or framework as a complement to language-specific test skills. the goal is real assertions tied to observable behavior, not mock theater or coverage theater.
pytest -k single_test) and full-suite command.Discover and learn the test environment. before writing a single test, run the repository's focused test command and its full suite. confirm the runner, configuration, and CI invocation. inspect three existing tests in the same module or test suite to learn fixture structure, naming convention, mock boundaries, and assertion patterns. understand the difference between fast-feedback focused runs and complete-suite runs. use the project's tracked test scripts, not global defaults. this step takes 5 minutes and prevents 30 minutes of rework.
Derive test cases from acceptance criteria and actual behavior. map each acceptance criterion to a discriminating case: a test that a plausible wrong implementation fails. name tests by observable outcome (e.g., test_returns_404_when_resource_missing, not test_get). write one behavior per test. make fixtures adversarial on the axis under test (if testing retry logic, set up a flaky responder; if testing concurrency, add contention). skip tests that restate framework behavior or test framework code; you own your contract, not theirs.
Apply the vertical-slice test rhythm. for bug reproducers: write a test that demonstrates the failure, observe it fail, apply the smallest fix, then observe it pass. if the bug cannot be triggered through existing test seams, follow the missing-seam protocol in test-completion.md. for new features: choose tests-after (default, one slice at a time) or tests-first (if explicitly chosen). if tests-first, write one test, implement minimal code to pass it, refactor, repeat per slice. horizontal slicing (all tests first, then all implementation) is an anti-pattern that produces tests for imagined behavior. after green, refactor with confidence. never alter an assertion, fixture, snapshot, or expected output to make the implementation pass; that inverts the contract.
Use real internals and real side effects; mock only external boundaries. prefer real file I/O (with temp directories), real in-process databases (SQLite for tests, not mocks of database calls), and real internal objects. mock only external boundaries (HTTP endpoints, external APIs, message queues) at the last owned adapter. framework-provided fakes (in-memory databases, fake HTTP clients provided by the framework) are fine where the framework recommends them. before mocking an external service, check its real contract, latency, and side effects. a mock that does not match the real contract is worse than a slow test.
Assert consumer-visible outcomes, not implementation details. assert what a user, caller, or downstream system observes: HTTP status codes, returned values, file contents, database state, log messages. do not assert private fields, call counts on mocks, or framework internals. include boundary cases (empty input, max size, null), invalid input (malformed, wrong type), concurrency hazards (race conditions, deadlock), and error paths (network failure, permission denied). if error handling catches, logs, substitutes, or rolls back, assert both the observable result and error visibility (e.g., log line present or exception propagated).
Prove absence and isolation with mutation controls. to assert that something must not happen (e.g., no double-charge, no concurrent mutation), write a test with a run-unique forbidden violation injected (e.g., add a flag that forces a second charge). observe that the test fails on the unpatched code. confirm the control landed and the build completed. remove the control, restore the artifact, verify green again. this pattern catches subtle regressions that passive assertions miss.
Run focused checks during edits; run complete checks before handoff. during development, run narrow test commands (single test, single file) for fast feedback. before submitting, run the full suite that CI runs. inspect passed/executed counts. an empty suite, skipped suite, or suite that reports zero assertions is not positive evidence. confirm test counts match your expectations.
test_module.py, module.spec.ts, ModuleTest.php).