Why Claude Code writes tests that don't actually test anything
Claude's tests pass. This is nearly guaranteed — it writes the implementation and the tests at the same time, so they're consistent with each other. Consistent isn't the same as correct.
The three patterns that produce empty tests
Testing the mock, not the behavior. Claude mocks out the dependencies and then tests that the mock was called. The test passes. The actual behavior of the function — what it does with the result — isn't tested.
Testing implementation details. The test verifies that a specific internal variable has a specific value, rather than that the function's output is correct. If you refactor the implementation, the test breaks even though nothing changed for callers.
Tests that can't fail. The assertion is something that's always true: checking that a function returns, checking that an array is defined, asserting the result is truthy without specifying what it should be.
The prompt that catches this
After Claude writes tests, add this:
For each test you wrote: what would happen if the function
returned the wrong value? Would the assertion catch it?
For each test that wouldn't catch a wrong return value,
rewrite the assertion so it would.
This forces Claude to think about what each assertion actually checks. It catches the "testing the mock" pattern, the always-true assertions, and the tests that verify structure instead of behavior.
The mutation test mental model
A simpler version: for each assertion, mentally change the function to return something obviously wrong (an empty string, null, the wrong number). Would the test fail? If not, the assertion isn't testing anything.
Claude can do this analysis if you ask it to. Ask before committing tests, not after you've been relying on them for a month.
Test-first with Claude
The most reliable fix: write the tests before the implementation. Tell Claude: "Write the tests first. The tests should fail on a stub implementation that returns null. Then write the implementation that makes them pass."
When Claude writes tests first, it can't make them pass trivially — they have to actually test something, because they're written against an interface that doesn't exist yet.
The Agent Prompt Playbook has the test quality prompt plus the TDD workflow for Claude Code. $29.