Write adversarial test cases that break production code instead of producing false confidence. Use when writing, reviewing, or planning tests for any codebase. Triggers on: "write tests", "add test coverage", "test this function", "create unit tests", "integration tests", "fix flaky tests", "improve test coverage", "review test quality", "are these tests good", "test plan", "break this code", "find edge cases", or any task involving pytest, vitest, jest, or other test frameworks. Enforces the prime directive — a test that cannot fail is not a test — and prevents common AI testing pitfalls: over-mocking, testing frameworks instead of production code, fake implementations that bypass real logic, and assertion-free tests.
A test is not a certificate that the code works. It is an attack on the code. You are not the
author defending the implementation — you are the adversary trying to make it produce a wrong
answer, crash, corrupt state, or silently do nothing.
The bar is not "the test passes." The bar is:
If the implementation were wrong, would this test catch it?
If a test cannot fail, it is not a test. It is decoration that makes the suite look green while
bugs ship. Green-on-first-write is a smell, not a success — it usually means the test was
written to mirror what the code already does, so it can only ever agree with it.
Three consequences follow, and they are non-negotiable:
Every test must be falsifiable. There must exist a plausible bug that turns it red.
Prove falsifiability — don't assume it. Break the code and watch the test fail (see the
Mutation Check below). A test you never saw fail is an unverified claim.
Write tests against the code's blind spots, not its happy path. After building a feature,
the job is to hunt the scenarios the implementation forgot to handle — not to re-enact the
ones it obviously handles.
The Mutation Check (The Real Bar)
After writing a test, deliberately break the production code and re-run it. The test must go
red. If it stays green, the test is worthless — delete or rewrite it.
Pick a mutation that mirrors a bug a real engineer would ship:
Mutation
Catches
Flip a comparison (> → >=, == → !=)
Off-by-one and boundary bugs
Invert a condition (if x → if not x)
Branch routing bugs
Delete a validation / guard clause
Missing input rejection
Return a constant instead of the computed value
Assertions that don't check the real output
Swap two arguments at a call site
Positional-argument mixups
Remove an await / drop the error handler
Async and failure-path bugs
Delete the function body entirely (return None)
The Deletion Test — the weakest gate
Then restore the code and confirm the suite is green again. Red-on-broken plus green-on-fixed
is the only evidence that a test is real. Never leave a mutation in the working tree.
The Deletion Test (Minimum Gate)
The cheapest mutation, applied mentally before you even run anything:
If the production code this test targets were deleted entirely, would this test still pass?
If yes, the test is worthless — it exercises framework plumbing, not production logic. Passing the
Deletion Test is necessary but not sufficient: a test can import the real function, exercise it,
and still be blind to every bug in it. The Mutation Check is the real bar.
Core Workflow
Identify the production code under test — find the exact function, class, or endpoint
Read it — understand its real logic, branches, edge cases, and dependencies
Hunt the gaps first — before writing a single assertion, enumerate what the code forgot to
handle: unvalidated inputs, unhandled failure modes, boundaries, concurrent access, partial
writes. See references/breaking-the-code.md. These gaps are
the test plan.
Apply the import rule — the test file MUST import from production code
Choose the right mock boundary — mock I/O at the edges, never mock the thing being tested
Write assertions against real behavior — assert on return values, state changes, side effects
that matter. Assert what the code should do, derived from the requirement — never what it
currently happens to return.
Run the Mutation Check — break the code, watch the test go red, restore the code, watch it go
green. A test you have not seen fail is not yet a test.
When a Test Finds a Bug, That Is Success
An adversarial test that goes red on correct-looking production code has done its job. Do not soften
the test to make it pass, do not relax the assertion, do not mark it xfail/skip to get to green.
Report the failure with the evidence and fix the production code at the root. The suite going green
by weakening the tests is the exact failure mode this skill exists to prevent.
The Five Laws of Accurate Tests
Law 1: Import Production Code
Every test file must import the actual production function/class it claims to test.
# WRONG — tests LangGraph, not your app
from langgraph.graph import StateGraph
graph = StateGraph(MessagesState)
graph.add_node("echo", lambda s: {"messages": [AIMessage(content="Echo")]})
# RIGHT — tests your app
from app.agents.core.graph_builder.build_graph import build_comms_agent
graph = build_comms_agent(checkpointer=MemorySaver())
Law 2: Mock at the Boundary, Not the Core
Mock external I/O (network, database, filesystem). Never mock the logic under test.
# WRONG — mocks the function being tested, tests nothing
with patch("app.services.chat_service.run_chat_stream") as mock:
mock.return_value = "response"
result = run_chat_stream(msg) # just calls the mock
# RIGHT — mocks the dependency, tests the real function
with patch("app.services.chat_service.llm_client.invoke") as mock_llm:
mock_llm.return_value = AIMessage(content="hello")
result = run_chat_stream(msg) # runs real logic, fake LLM
Law 2b: Patch Module Singletons, Not Individual Functions
When production code uses a module-level singleton (a shared client, cache, or connection object), patch the singleton's attribute directly. This ensures all production code that touches the singleton — including code several layers deep — uses the real test resource without any function-level patching.
# Production: redis_cache = RedisCache() (module singleton)
# StreamManager uses redis_cache.redis internally
# WRONG — patches one function, misses all others that use redis_cache
with patch("app.core.stream_manager.StreamManager.publish_chunk") as mock:
... # other methods still use the broken/missing redis_cache.redis
# RIGHT — patch the singleton attribute; all production code sees real Redis
from app.db.redis import redis_cache
@pytest.fixture
async def real_redis(monkeypatch):
client = Redis.from_url("redis://localhost:6379", decode_responses=True)
await client.ping()
monkeypatch.setattr(redis_cache, "redis", client) # one patch, everything works
yield client
await client.flushdb()
await client.aclose()
async def test_stream_publishes(real_redis):
await StreamManager.start_stream("s1", "conv1", "user1")
await StreamManager.publish_chunk("s1", "data: hello\n\n")
chunks = []
async for chunk in StreamManager.subscribe_stream("s1"):
chunks.append(chunk)
break
assert chunks[0] == "data: hello\n\n"
Law 3: Assert on Production Behavior
Assert on what the production code actually does — return values, state mutations, raised exceptions, emitted events.
# WRONG — asserts mock was called (tests your test setup)
mock_service.process.assert_called_once_with(data)
# RIGHT — asserts the actual outcome
result = process_email(raw_email)
assert result.subject == "Re: Meeting"
assert result.is_read is False
assert len(result.attachments) == 2
Law 4: Cover Real Branches
Read the production code. Find the if/elif/else, try/except, and early returns. Write a test for each path.
# Production code has: if user.is_premium: ... else: ...
# Test BOTH paths
def test_premium_user_gets_extended_features(): ...
def test_free_user_gets_basic_features(): ...
Law 5: Test Error Paths, Not Just Happy Paths
Production bugs cluster in error handling. Test what happens when dependencies fail.
def test_handles_api_timeout():
with patch("app.tools.gmail.client.send") as mock:
mock.side_effect = httpx.TimeoutException("timeout")
result = send_email(to="x@y.com", body="hi")
assert result.error == "Failed to send: timeout"
Scenario Hunt: Attack What the Code Forgot to Handle
Coverage of the branches that exist is the floor, not the ceiling. Law 4 tests the if/else the
author wrote. The bugs live in the cases the author never wrote a branch for.
After a feature is built, go hunting. For every input, dependency, and piece of state the code
touches, ask: what value or timing would this code not survive? Then write that test.
First, last, one-below, one-above, exactly-at the limit? Empty collection, single element?
Failure modes
Dependency times out, returns an error, returns garbage, returns None, raises mid-iteration?
State
Called twice, called out of order, called after failure, called on a half-written record?
Authorization
Another user's ID, a revoked token, a resource that no longer exists?
Volume
Duplicates, pagination edges, a payload larger than any assumed limit?
Each row that the production code does not survive is either a bug to fix or a requirement to
make explicit. Both outcomes are wins. The full playbook, with per-type checklists and worked
examples, is in references/breaking-the-code.md.
Anti-Pattern Detection
When writing or reviewing tests, check for these red flags. For detailed examples and fixes, see references/anti-patterns.md.
Red Flag
What It Means
The test cannot be made to fail by any plausible bug
Not a test — it is decoration
Test was never observed failing (no Mutation Check run)
Falsifiability is an unverified claim
Assertion was written by reading the code's current output
Tests what the code does, so it can never disagree with it
Suite is 100% happy-path
The bugs are in the paths you didn't write
A failing test was relaxed, skipped, or xfailed to get to green
Suppressing the bug, not fixing it
Test file has zero imports from app/ or src/
Tests framework, not production code
More @patch decorators than assertions
Over-mocking — testing your mock setup
Test builds its own graph/pipeline from scratch
Tests the framework's graph builder, not your graph
Assertions only check mock.called or mock.call_count
Proves nothing about production behavior
Test defines a fake implementation of the thing being tested
Circular — testing your fake, not production code
# mimicking, # simplified version of in comments
Admission that production code is not under test
Test manually reimplements what a production function does
Duplication — if you delete the function, test still passes
All tests pass when production code is broken
The entire suite is false confidence
Mock Hierarchy (What to Mock Where)
Test Type
Mock
Don't Mock
Unit
DB clients, HTTP clients, message queues, filesystem
The function under test, its direct logic
Integration
LLM API calls, external SaaS APIs (Composio, Stripe)
Your service layer, your DB queries, your routing
E2E
LLM (use fake model), external APIs (use recorded responses)
Your entire pipeline — graph, routing, services, DB
Language-Specific Guidance
Python (pytest): See references/pytest-patterns.md for fixture design, parametrize patterns, and conftest hierarchy
TypeScript (vitest/jest): See references/vitest-patterns.md for module mocking, type-safe mocks, and async patterns
Pre-Commit Checklist
Before finalizing any test:
I broke the production code and watched this test fail, then restored it and watched it pass
I can name the specific bug this test would catch
Assertions come from the requirement, not from the code's current output
Test imports the production function/class directly
Removing the production code would break this test
Assertions check return values or state, not just mock calls
Each branch in production code has a corresponding test case
Error/exception paths are tested — the suite is not all happy-path
The Scenario Hunt ran: boundaries, bad inputs, dependency failures, out-of-order calls
No test was weakened, skipped, or xfailed to turn the suite green
No mutation was left behind in the production code
Mock count is proportional to external dependencies, not internal logic
Test name describes the behavior being verified, not the implementation
1---2name: accurate-testing-23description: Write adversarial test cases that break production code instead of producing false confidence. Use when writing, reviewing, or planning tests for any codebase. Triggers on: "write tests", "add test coverage", "test this function", "create unit tests", "integration tests", "fix flaky tests", "improve test coverage", "review test quality", "are these tests good", "test plan", "break this code", "find edge cases", or any task involving pytest, vitest, jest, or other test frameworks. Enforces the prime directive — a test that cannot fail is not a test — and prevents common AI testing pitfalls: over-mocking, testing frameworks instead of production code, fake implementations that bypass real logic, and assertion-free tests.4---56# Accurate Testing78## Prime Directive: Tests Exist to Break the Code910A test is not a certificate that the code works. It is an **attack** on the code. You are not the11author defending the implementation — you are the adversary trying to make it produce a wrong12answer, crash, corrupt state, or silently do nothing.1314The bar is not "the test passes." The bar is:1516> **If the implementation were wrong, would this test catch it?**1718If a test cannot fail, it is not a test. It is decoration that makes the suite look green while19bugs ship. Green-on-first-write is a **smell**, not a success — it usually means the test was20written to mirror what the code already does, so it can only ever agree with it.2122Three consequences follow, and they are non-negotiable:23241. **Every test must be falsifiable.** There must exist a plausible bug that turns it red.252. **Prove falsifiability — don't assume it.** Break the code and watch the test fail (see the26 Mutation Check below). A test you never saw fail is an unverified claim.273. **Write tests against the code's blind spots, not its happy path.** After building a feature,28 the job is to hunt the scenarios the implementation *forgot to handle* — not to re-enact the29 ones it obviously handles.3031## The Mutation Check (The Real Bar)3233After writing a test, **deliberately break the production code** and re-run it. The test must go34red. If it stays green, the test is worthless — delete or rewrite it.3536Pick a mutation that mirrors a bug a real engineer would ship:3738| Mutation | Catches |39|----------|---------|40| Flip a comparison (`>` → `>=`, `==` → `!=`) | Off-by-one and boundary bugs |41| Invert a condition (`if x` → `if not x`) | Branch routing bugs |42| Delete a validation / guard clause | Missing input rejection |43| Return a constant instead of the computed value | Assertions that don't check the real output |44| Swap two arguments at a call site | Positional-argument mixups |45| Remove an `await` / drop the error handler | Async and failure-path bugs |46| Delete the function body entirely (`return None`) | The Deletion Test — the weakest gate |4748Then **restore the code** and confirm the suite is green again. Red-on-broken plus green-on-fixed49is the only evidence that a test is real. Never leave a mutation in the working tree.5051## The Deletion Test (Minimum Gate)5253The cheapest mutation, applied mentally before you even run anything:5455> If the production code this test targets were deleted entirely, would this test still pass?5657If yes, the test is worthless — it exercises framework plumbing, not production logic. Passing the58Deletion Test is necessary but **not sufficient**: a test can import the real function, exercise it,59and still be blind to every bug in it. The Mutation Check is the real bar.6061## Core Workflow62631. **Identify the production code under test** — find the exact function, class, or endpoint642. **Read it** — understand its real logic, branches, edge cases, and dependencies653. **Hunt the gaps first** — before writing a single assertion, enumerate what the code *forgot to66 handle*: unvalidated inputs, unhandled failure modes, boundaries, concurrent access, partial67 writes. See [references/breaking-the-code.md](references/breaking-the-code.md). These gaps are68 the test plan.694. **Apply the import rule** — the test file MUST import from production code705. **Choose the right mock boundary** — mock I/O at the edges, never mock the thing being tested716. **Write assertions against real behavior** — assert on return values, state changes, side effects72 that matter. Assert what the code *should* do, derived from the requirement — never what it73 currently happens to return.747. **Run the Mutation Check** — break the code, watch the test go red, restore the code, watch it go75 green. A test you have not seen fail is not yet a test.7677## When a Test Finds a Bug, That Is Success7879An adversarial test that goes red on correct-looking production code has done its job. Do not soften80the test to make it pass, do not relax the assertion, do not mark it `xfail`/`skip` to get to green.81Report the failure with the evidence and fix the production code at the root. The suite going green82by weakening the tests is the exact failure mode this skill exists to prevent.8384## The Five Laws of Accurate Tests8586### Law 1: Import Production Code8788Every test file must import the actual production function/class it claims to test.8990```python91# WRONG — tests LangGraph, not your app92from langgraph.graph import StateGraph93graph = StateGraph(MessagesState)94graph.add_node("echo", lambda s: {"messages": [AIMessage(content="Echo")]})9596# RIGHT — tests your app97from app.agents.core.graph_builder.build_graph import build_comms_agent98graph = build_comms_agent(checkpointer=MemorySaver())99```100101### Law 2: Mock at the Boundary, Not the Core102103Mock external I/O (network, database, filesystem). Never mock the logic under test.104105```python106# WRONG — mocks the function being tested, tests nothing107with patch("app.services.chat_service.run_chat_stream") as mock:108 mock.return_value = "response"109 result = run_chat_stream(msg) # just calls the mock110111# RIGHT — mocks the dependency, tests the real function112with patch("app.services.chat_service.llm_client.invoke") as mock_llm:113 mock_llm.return_value = AIMessage(content="hello")114 result = run_chat_stream(msg) # runs real logic, fake LLM115```116117**Law 2b: Patch Module Singletons, Not Individual Functions**118119When production code uses a module-level singleton (a shared client, cache, or connection object), patch the singleton's attribute directly. This ensures all production code that touches the singleton — including code several layers deep — uses the real test resource without any function-level patching.120121```python122# Production: redis_cache = RedisCache() (module singleton)123# StreamManager uses redis_cache.redis internally124125# WRONG — patches one function, misses all others that use redis_cache126with patch("app.core.stream_manager.StreamManager.publish_chunk") as mock:127 ... # other methods still use the broken/missing redis_cache.redis128129# RIGHT — patch the singleton attribute; all production code sees real Redis130from app.db.redis import redis_cache131132@pytest.fixture133async def real_redis(monkeypatch):134 client = Redis.from_url("redis://localhost:6379", decode_responses=True)135 await client.ping()136 monkeypatch.setattr(redis_cache, "redis", client) # one patch, everything works137 yield client138 await client.flushdb()139 await client.aclose()140141async def test_stream_publishes(real_redis):142 await StreamManager.start_stream("s1", "conv1", "user1")143 await StreamManager.publish_chunk("s1", "data: hello\n\n")144 chunks = []145 async for chunk in StreamManager.subscribe_stream("s1"):146 chunks.append(chunk)147 break148 assert chunks[0] == "data: hello\n\n"149```150151### Law 3: Assert on Production Behavior152153Assert on what the production code actually does — return values, state mutations, raised exceptions, emitted events.154155```python156# WRONG — asserts mock was called (tests your test setup)157mock_service.process.assert_called_once_with(data)158159# RIGHT — asserts the actual outcome160result = process_email(raw_email)161assert result.subject == "Re: Meeting"162assert result.is_read is False163assert len(result.attachments) == 2164```165166### Law 4: Cover Real Branches167168Read the production code. Find the `if/elif/else`, `try/except`, and early returns. Write a test for each path.169170```python171# Production code has: if user.is_premium: ... else: ...172# Test BOTH paths173def test_premium_user_gets_extended_features(): ...174def test_free_user_gets_basic_features(): ...175```176177### Law 5: Test Error Paths, Not Just Happy Paths178179Production bugs cluster in error handling. Test what happens when dependencies fail.180181```python182def test_handles_api_timeout():183 with patch("app.tools.gmail.client.send") as mock:184 mock.side_effect = httpx.TimeoutException("timeout")185 result = send_email(to="x@y.com", body="hi")186 assert result.error == "Failed to send: timeout"187```188189## Scenario Hunt: Attack What the Code Forgot to Handle190191Coverage of the branches that *exist* is the floor, not the ceiling. Law 4 tests the `if/else` the192author wrote. The bugs live in the cases the author never wrote a branch for.193194After a feature is built, go hunting. For every input, dependency, and piece of state the code195touches, ask: **what value or timing would this code not survive?** Then write that test.196197| Attack surface | Ask |198|----------------|-----|199| **Inputs** | Empty, null/`None`, zero, negative, unicode, whitespace-only, absurdly long, wrong type, malformed? |200| **Boundaries** | First, last, one-below, one-above, exactly-at the limit? Empty collection, single element? |201| **Failure modes** | Dependency times out, returns an error, returns garbage, returns `None`, raises mid-iteration? |202| **State** | Called twice, called out of order, called after failure, called on a half-written record? |203| **Authorization** | Another user's ID, a revoked token, a resource that no longer exists? |204| **Volume** | Duplicates, pagination edges, a payload larger than any assumed limit? |205206Each row that the production code does not survive is either a **bug to fix** or a **requirement to207make explicit**. Both outcomes are wins. The full playbook, with per-type checklists and worked208examples, is in [references/breaking-the-code.md](references/breaking-the-code.md).209210## Anti-Pattern Detection211212When writing or reviewing tests, check for these red flags. For detailed examples and fixes, see [references/anti-patterns.md](references/anti-patterns.md).213214| Red Flag | What It Means |215|----------|--------------|216| The test cannot be made to fail by any plausible bug | Not a test — it is decoration |217| Test was never observed failing (no Mutation Check run) | Falsifiability is an unverified claim |218| Assertion was written by reading the code's current output | Tests what the code *does*, so it can never disagree with it |219| Suite is 100% happy-path | The bugs are in the paths you didn't write |220| A failing test was relaxed, `skip`ped, or `xfail`ed to get to green | Suppressing the bug, not fixing it |221| Test file has zero imports from `app/` or `src/` | Tests framework, not production code |222| More `@patch` decorators than assertions | Over-mocking — testing your mock setup |223| Test builds its own graph/pipeline from scratch | Tests the framework's graph builder, not your graph |224| Assertions only check `mock.called` or `mock.call_count` | Proves nothing about production behavior |225| Test defines a fake implementation of the thing being tested | Circular — testing your fake, not production code |226| `# mimicking`, `# simplified version of` in comments | Admission that production code is not under test |227| Test manually reimplements what a production function does | Duplication — if you delete the function, test still passes |228| All tests pass when production code is broken | The entire suite is false confidence |229230## Mock Hierarchy (What to Mock Where)231232| Test Type | Mock | Don't Mock |233|-----------|------|------------|234| **Unit** | DB clients, HTTP clients, message queues, filesystem | The function under test, its direct logic |235| **Integration** | LLM API calls, external SaaS APIs (Composio, Stripe) | Your service layer, your DB queries, your routing |236| **E2E** | LLM (use fake model), external APIs (use recorded responses) | Your entire pipeline — graph, routing, services, DB |237238## Language-Specific Guidance239240- **Python (pytest)**: See [references/pytest-patterns.md](references/pytest-patterns.md) for fixture design, parametrize patterns, and conftest hierarchy241- **TypeScript (vitest/jest)**: See [references/vitest-patterns.md](references/vitest-patterns.md) for module mocking, type-safe mocks, and async patterns242243## Pre-Commit Checklist244245Before finalizing any test:246247- [ ] **I broke the production code and watched this test fail, then restored it and watched it pass**248- [ ] I can name the specific bug this test would catch249- [ ] Assertions come from the requirement, not from the code's current output250- [ ] Test imports the production function/class directly251- [ ] Removing the production code would break this test252- [ ] Assertions check return values or state, not just mock calls253- [ ] Each branch in production code has a corresponding test case254- [ ] Error/exception paths are tested — the suite is not all happy-path255- [ ] The Scenario Hunt ran: boundaries, bad inputs, dependency failures, out-of-order calls256- [ ] No test was weakened, skipped, or `xfail`ed to turn the suite green257- [ ] No mutation was left behind in the production code258- [ ] Mock count is proportional to external dependencies, not internal logic259- [ ] Test name describes the behavior being verified, not the implementation
Run npx skillmds@latest add theexperiencecompany/accurate-testing-2 in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Write adversarial test cases that break production code instead of producing false confidence. Use when writing, reviewing, or planning tests for any codebase. Triggers on: "write tests", "add test coverage", "test this function", "create unit tests", "integration tests", "fix flaky tests", "improve test coverage", "review test quality", "are these tests good", "test plan", "break this code", "find edge cases", or any task involving pytest, vitest, jest, or other test frameworks. Enforces the prime directive — a test that cannot fail is not a test — and prevents common AI testing pitfalls: over-mocking, testing frameworks instead of production code, fake implementations that bypass real logic, and assertion-free tests. It is listed under Integrations & APIs on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: CAUTION, Skill Scanner: PASS. Capability flags: reads secrets. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
theexperiencecompany (@theexperiencecompany) published this skill. Their other Agent Skills are listed on their SkillMD profile.