My Tests Passed Because They Tested Nothing
We recently audited the test suites of every repository in our project. The audit found a group of tests and CI gates that I wrote and that reported passing without checking anything. Nothing had ever flagged them, because every one of them passed every gate. We only found them by reading each test and asking what it actually asserts.
That’s the uncomfortable part. A failing test gets attention. A test that passes for the wrong reason can sit in the suite for months and make everyone trust the code more than they should. Here’s what I got wrong, what it cost, and what I’m doing differently.
What I did wrong
1. Tests that skipped themselves by returning, and counted as passes
Some of our tests need a particular environment, such as a container runtime configured a certain way or the ability to trigger out-of-memory conditions. When I wrote them, I added a check at the top: if the environment isn’t suitable, return.
To the test runner, a test that returns normally has passed. One of these tests needs a setup that none of our CI images provide, so it has never run in CI. The pipeline reported it green every time anyway. We had a row of green checkmarks for code paths that had never executed.
2. A live call to a paid API in the default suite
I put a test that calls a real third-party API, a paid one, into the default test suite. When credentials were missing, it passed silently. That’s the worst of both cases:
- In CI, without credentials, it was a passing test that made no call and checked nothing.
- With credentials, it was a paid network call inside a gate. It cost money, could fail when the network was flaky, and tied our build to someone else’s uptime.
3. A gate that compiled everything and ran nothing
I set up a CI gate to run the doc-comment examples across a workspace. It compiled all of them on every run, which took about a minute and a half, and then ran zero. Every fenced block in those doc comments was a configuration snippet, not runnable code, so there was nothing to execute.
The gate reported success because nothing failed, and nothing failed because nothing ran. Checking whether the doc comments contain code fences wouldn’t have caught this, because they do. The fix was to have the gate count the examples it actually ran.
4. Tests that read the fixture back to itself
This was the largest group. Our protocol types exist in two languages, a Rust backend and a TypeScript client, and I wrote tests that looked thorough but weren’t:
- Parse-and-read-back tests. Dozens of TypeScript tests parse a JSON literal, cast it to a type, and assert that the fields equal the values in that same literal. That tests the JSON parser. It doesn’t catch fields nobody reads, type changes, or whether the TypeScript shape matches what the Rust side actually serializes.
- Duplicated constants. Several shared constants, like page sizes and limits, are defined once in Rust and once in TypeScript. Each copy had a test pinning it to a hard-coded value. If the two copies drift apart, both suites stay green, because each one only checks itself.
- Restated tables. About a hundred small one-line version predicates had roughly 140 hand-written tests, plus a third copy in doc examples. The tests repeated the predicate table instead of deriving from it. If a row is wrong in the code and in the test, which is easy when you copy one into the other, the test passes.
5. Lint rules written as tests
A few client tests scan source files and stylesheets to enforce conventions. They’re cheap and they work, but they’re in the wrong place. When one fails, it looks like broken behaviour rather than a style violation, and it runs on every test invocation instead of while you’re editing.
What it caused
- The pipeline reported passing tests for container and memory-limit paths it never ran, including one that no CI environment could run.
- A paid external call sat inside the default test suite.
- Every run of one gate spent about 95 seconds compiling examples that didn’t exist.
- The Rust and TypeScript copies of our protocol could drift apart with both suites green.
None of this broke production as far as we know. But the protection we thought we had wasn’t there.
What I should have written
Skips should go through the runner, so they’re reported as skips. Test frameworks have mechanisms for this, such as ignore attributes paired with an opt-in profile, or conditional skipIf. Then the report says “skipped” instead of “passed”. A test should never return early and pass.
External and paid calls belong in an opt-in profile. The same goes for tests that measure wall-clock performance. They run deliberately, outside the gates that guard every merge.
Gates should report what they ran. The doc-example gate should count the examples it executed and treat zero as a configuration error, or skip itself for crates whose doc comments have no runnable code.
When two implementations share a contract, the tests should compare them. The Rust side should produce fixtures from its real serialization, and the TypeScript tests should read those fixtures. Then each copy is checked against the other instead of against itself. Shared constants should come from one source or be checked against each other.
Tables should have one source. Predicate tests should be table-driven from a single table, not written out again by hand.
Convention checks belong in the linter. Source-scanning rules should be lint rules, so they run at edit time and read as style problems.
Not every simple assertion is a bad one
The audit also flagged some tests that turned out to be correct. A second review pass rejected those findings, and I think they matter as much as the real problems:
- Tests that pin exact wording to the design spec. These are intentional. We want the code tied to the design.
- Tests that only assert that nothing throws. For some guard clauses, not throwing is the specified behaviour.
- Round-trip tests in files that also check the exact wire format. The other checks already cover what the round trip can’t.
- Tests that check a refusal happened without checking its text. The text is prose, and asserting it would only add a test that fails on every rewording.
So the lesson isn’t to delete every test that compares against a literal. Before calling a test weak, find the requirement it pins. A hard-coded value or a no-throw assertion is correct when that value or that behaviour is the requirement.
How I’ll catch this in review
These are the patterns I now look for, in my own code and in code I review:
- A
returnbehind an environment check at the top of a test is a skip that reports as a pass. Use the runner’s skip mechanism. - A test named “live,” or one that reads credentials from the environment, makes an external call. It belongs behind an opt-in profile. Passing silently when the credential is missing is never acceptable.
- A gate that takes real time but doesn’t report a test count may be doing nothing. Every gate should say what it ran.
- A test whose expected value comes from the same literal as its input is testing the parser, not the type. If two implementations of a contract exist, the test has to compare them.
- Before flagging a literal or no-throw assertion as weak, I find the requirement it covers.
I’ve added these rules to our team’s coding guidelines, and each fix is now tracked as its own task. The broader lesson for me is that a green test suite only tells you nothing failed. It doesn’t tell you anything was checked.