Well Defined: The Second Quality of Valuable Tests
Understand what makes a test well defined by exploring how to achieve consistent and repeatable test results in Rails. Learn to handle challenges from time, randomness, and third-party dependencies through encapsulation and mocking techniques, improving the reliability of your application's test suite.
We'll cover the following...
Well defined
A test is well-defined if running the same test repeatedly gives the same result. If the test is not well defined, the symptom will be intermittent, seemingly random test failures (sometimes called Heisenbugs, Heisenspecs, or Rando Calrissian).
Repeatability problems
The three classic causes of repeatability problems are:
- Time and date testing
- Random numbers
- Third-party or Ajax calls
These all have the same root cause: ensuring that each test is run in a consistent environment is impossible. Dates and times have a nasty habit of never staying the same. The time is continually increasing, ...