Yeda AI Tips · #151

Español

Read the Tests Before the Code

Review the tests first. The code second. Most reviewers open a pull request and scroll straight to the implementation — the new function, the changed branch, the clever refactor. But the diff already contains a plain-English spec of what the change is supposed to do: the tests. Read them first and you review with intent in hand instead of reverse-engineering it from the code.

Why tests come first

A test is the author telling you, in executable form, what behavior this change guarantees. It names the inputs, the expected outputs, and the edge cases the author thought mattered. That's the contract. Google's own code-review guide puts tests on the short list of things a reviewer must actively evaluate — not skim — because "tests do not test themselves, and we rarely write tests for our tests; a human must ensure that tests are valid."

Read the code first and you spend your attention decoding how it works. Read the tests first and you already know what it's supposed to do — so when you read the code, you're checking it against a spec instead of guessing at one. Tests also age better than comments: they're living documentation that fails when the behavior drifts, so what you read in the diff is current, not stale.

The mechanism

  1. Read the tests in the diff first. Note the behaviors they assert and the edge cases they cover. This is the author's stated intent.
  2. Read the code against them. Now every line answers a question you already framed: does this satisfy the contract the tests describe?
  3. Hunt the gap. The change touches a risky path — a new branch, an error case, a concurrency window, a boundary. Is there a test for it? A risky change with no test on its risky path is itself a finding. Write that comment.
You see in the diffWhat to checkRed flag
A new testWill it fail when the code is broken?Asserts nothing that can go wrong
A changed testWhy did the expectation change?Loosened to make a bug pass
A new branch / error pathIs there a test that exercises it?Untested risky path
No test change at allShould there be one?"Refactor" that alters behavior

Green isn't reviewed

Passing tests mean the code satisfies the tests that exist. They say nothing about the tests that should exist. A change can be fully green and still ship an untested failure mode — the CI checkmark only covers the paths someone remembered to write. Reading tests first is how you catch the risky path the change quietly introduced, because you're comparing the set of tested behaviors against the set of changed behaviors and looking for the difference.

For the power user

Resources

<div class="cta"> <p><strong>Shipping AI agents that review or write code?</strong> Yeda AI designs, audits, and ships production LLM systems.</p> <p>More tips in the series · <a href="/contact">Talk to us</a></p> </div>