{"slug":"testing-conventions","title":"testing-conventions","summary":"How to write a good test: behaviour-describing names (`should_return_error_when_input_is_empty`, `given_when_then`), exact-value assertions over truthiness, snapshot and property-based testing, order-independent and idempotent tests with no shared mutable state, and the anti-patt","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-10-16T16:28:43.694527Z","repo":{"url":"https://github.com/Goldziher/ai-rulez","stars":162,"forks":16,"license":"MIT","updatedAt":"2026-10-16T13:56:06Z"},"bodyHtml":"<hr>\n<h2>name: testing-conventions\ndescription: \"How to write a good test: behaviour-describing names (<code>should_return_error_when_input_is_empty</code>, <code>given_when_then</code>), exact-value assertions over truthiness, snapshot and property-based testing, order-independent and idempotent tests with no shared mutable state, and the anti-patterns (testing mocks, test-only production methods, mocking what you don't own, asserting implementation details). Load when writing or reviewing a test file, naming test cases, choosing assertions, or diagnosing a flaky or always-passing test.\"</h2>\n<h2>Naming</h2>\n<p>Name tests to describe behaviour: <code>should_return_error_when_input_is_empty</code>, <code>test_parse_handles_nested_objects</code>. Use <code>describe</code>/<code>it</code> blocks for grouping where the language supports them. Follow <code>given_when_then</code> or <code>should_when</code>. Test names are specifications — a reader should understand the expected behaviour without reading the body.</p>\n<h2>Assertions</h2>\n<p>Assert exact expected values, not truthiness (<code>assert result == 42</code>, not <code>assert result</code>). Use snapshot testing for complex structured output and property-based testing for functions with wide input ranges. Include descriptive failure messages. Always test error paths and edge cases, not just the happy path. Use parameterized tests or fixtures for input variations instead of copy-paste. Do not test that an exception class or function merely exists.</p>\n<h2>Independence</h2>\n<p>Tests must be independent and idempotent — runnable in any order, in parallel. No shared mutable state between tests. Use factories or fixtures for setup. Clean up created resources (files, DB rows, env vars) after each test. Never rely on execution order. Mock only the external boundary (network, third-party services, clocks); use real objects for everything else.</p>\n<h2>Anti-patterns</h2>\n<ul>\n<li>Do not test mock behaviour instead of real behaviour.</li>\n<li>Do not add test-only methods to production code.</li>\n<li>Do not mock what you don't own — wrap it and test the wrapper.</li>\n<li>Do not test implementation details — test observable behaviour.</li>\n<li>Do not write tests that pass when the code is broken. If a test never fails, it is not testing anything.</li>\n<li>When adding tests to existing code, never edit the code under test to make a test pass. If a test can only pass that way, it found a bug: surface it. In a red-green cycle the failing test comes first and the code change is the point. Fixing the test's own scaffolding, mocks or assertions is always in scope.</li>\n<li>Do not skip, xfail or weaken a failing test to get green. A skipped test or vacuous pass hides a gap.</li>\n</ul>\n<h2>Verify the test can fail</h2>\n<p>After a test passes, break or revert the fix and confirm it fails for the reason you expect. A test file the runner does not collect, or an empty fixture, passes while testing nothing: check that the test actually ran.</p>\n","files":[{"path":"SKILL.md","sizeBytes":2815,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-10-16T16:29:44.841252Z","sha256":"5ABC4B8AD0C7E4E928F815EA825E3A17F98BFA89A888EEBEACC2856C91CED762","sizeBytes":1429},"review":null,"source":{"repositoryUrl":"https://github.com/Goldziher/ai-rulez","path":"internal/builtins/universal/testing/skills/testing-conventions","license":"MIT","commit":"ca967ad555fc84aa6e3594648676f209d4e8b546","subtreeSha":"F0D9CEBAC6F8E828F05DCBCA36D3A2FD769E90CF4B7D8D47D0BB91293F98035F","lastSyncedAt":"2026-10-16T16:28:36.671871Z"},"reviewedAt":"2026-10-16T16:32:23.239573Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/Goldziher/ai-rulez/tree/main/internal/builtins/universal/testing/skills/testing-conventions"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install goldziher-ai-rulez@llmmart"},{"target":"git","command":"git clone https://github.com/Goldziher/ai-rulez.git"}]}