Tests that always pass, and other quiet failures
How to spot the generated tests that look like protection and provide none.
The most dangerous test is not the one that fails. It is the one that always passes. It looks like protection and provides none. Learn to spot the common shapes.
The assertion that checks nothing. A test that confirms a field exists, or that a result is not null, without checking its value. It passes even when the value is wrong.
Asserting the wrong thing. The test checks a side effect that happens to hold rather than the behavior you care about. Green, but pointed at the wrong target.
The tautology. The test computes the expected value using the same code it is testing, so the two can never disagree.
Over-mocked to meaninglessness. So much is stubbed that the test exercises the mocks, not the real logic.
Structural coverage hides all of these. A line can be covered, and counted, by a test that asserts nothing. Coverage measures execution, not verification.
The tell is confidence without evidence. When a freshly generated suite is entirely green on the first run over untested code, be suspicious rather than pleased. Real tests find real problems, and new tests over old code usually surface at least one surprise.
Scan a test file for assertions that only check existence or non-null. Pick one and strengthen it to assert the exact expected value. Confirm it still passes for the right reason.
Enjoying the free lessons? Get an email when we publish new courses and updates — no spam, unsubscribe anytime.
Discussion (0)
Ask a question or share what worked for you. Comments are reviewed before they appear.
No comments yet. Be the first to start the discussion!