Testing conventions

From Goldziher/ai-rulez · View interactive version

Testing conventions is an AI agent skill from the GitHub repository Goldziher/ai-rulez. Writing tests: behavior-describing names, exact-value assertions, snapshot and property tests, independent idempotent tests, anti-patterns such as testing mocks. Use when writing or reviewing tests or diagnosing a flaky one.

How to use this skill

Skill file

Naming

Name tests to describe behaviour: should_return_error_when_input_is_empty, test_parse_handles_nested_objects. Use describe/it blocks for grouping where the language supports them. Follow given_when_then or should_when. Test names are specifications — a reader should understand the expected behaviour without reading the body.

Assertions

Assert exact expected values, not truthiness (assert result == 42, not assert result). 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.

Independence

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.

Anti-patterns

Verify the test can fail

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.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.