Detecting false negatives and false positives

Tests can fool us with failures when the code actually works fine (false negatives) and successes when the code is broken (false positives). There is no way to completely eliminate false results, but we can reduce their likelihood by keeping tests simple and doing sanity checks. Sometimes our tests might seem like they are not doing enough, or we may seem to be checking for redundant things that we expect never to break. That is simply the price we have to pay to minimize the chance that our tests are fooling us.

Let's cover three useful tactics to reduce false results:

  • Sanity checks
  • Tests for the opposite case
  • Increased specificity of assertions

Detecting false results is a fundamental concern of testing, ...

Get RSpec Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.