Lab Zero

How Do I Know When I've Written Enough Tests?


At Lab Zero, we use code coverage tools to tell us when we hit 100% line coverage. That’s a baseline. We typically go pretty far beyond the baseline.

But how do we know we’ve written enough tests? Here are some common things that your Lab Zero reviewer is likely to find in your test coverage:

  1. You covered the code, but you didn’t cover the story. If you don’t cover the happy path from the user’s perspective in the form of an integration test, you probably need to add it.
  2. You made a cosmetic change and you felt it might not need a test. But it turns out that the cosmetic change causes the existing test to fail, so you need to go back and update the existing test.
  3. You have 100% line coverage, but there’s one test you wrote that doesn’t test what you think it does. For example, your beacon is firing, but it’s firing as a side-effect of the test harness. Go back and fix it so that the intent is clear.
  4. You fixed a bug, but you didn’t add a test specifically for the bug. Add it.
  5. You’re not resetting your environment after each test, leading to a false sense of success. You have to reset conditions back to initial conditions so that you really have an opportunity to catch an error.
  6. You accept user input, but you don’t test for nonsense.
  7. You accept user input, but you don’t test for malicious input.
  8. You missed a boundary condition. Maybe you tested an extremely high value and an extremely low value, but you didn’t test a breakpoint value (such as a breakpoint screen resolution in a responsive design).
  9. If you add conditional logic, then you probably need to test the new branch.

 And remember, if your tests never fail, you’re testing the wrong things.


Continue the conversation.

Lab Zero is a San Francisco-based product team helping startups and Fortune 100 companies build flexible, modern, and secure solutions.