What to Do When Unit Tests Pass but Production Hates You
by Eric Hanson, Backend Developer at Clean Systems Consulting
Everything works on your machine, all unit tests green.
Then production screams, and suddenly you’re the villain.
Green Tests ≠ Safe Deployment
Unit tests are a safety net, not a crystal ball.
- They only cover the cases they were written for
- They don’t see production’s real-world data quirks
- They can’t predict environment-specific behavior
Passing tests make you confident, not invincible.
Step Back and Observe
When production fails, the first instinct is panic—but slow down.
- Check logs first: errors are rarely subtle
- Compare production input/output with what your tests used
- Look for hidden assumptions in the code
Your job is investigation, not blame.
Isolate the Problem
Production failures are rarely caused by a single line of code.
- Identify which service or module is misbehaving
- Verify configuration differences between staging and production
- Confirm dependencies, versions, and network behavior
Breaking it down avoids a frantic all-hands debugging session.
Communication Is Key
Once you know the problem, keep your team informed.
- Send clear updates to managers and stakeholders
- Document what fails, why, and what’s being tested next
- Avoid speculation or panic—clarity helps everyone act faster
Unit tests may have passed, but transparency wins the day.
Lessons for the Future
Use the incident to strengthen your safety net:
- Add integration or system tests for production-like scenarios
- Review environment parity between local, staging, and production
- Remember: tests are tools, not proof of perfection
Production will always throw curveballs—anticipate them, don’t fear them.