RubyConf 2023 - The Secret Ingredient: How To Understand and Resolve Just... by Alan Ridlehoover

Understand and resolve flaky tests in Ruby with Alan Ridlehoover, exploring non-determinism, order dependency, and race conditions, and learning practical techniques to fix flaky tests and improve testing efficiency.

Key takeaways
  • Flaky tests are a common issue in testing, leading to wasted time and frustration.
  • 3 main causes of flakiness: non-determinism, order dependency, and race conditions.
  • Non-determinism: when tests are dependent on external factors, such as time or network connectivity.
  • Order dependency: when tests are dependent on the order in which they are run.
  • Race conditions: when multiple tests compete for shared resources.
  • Flaky tests can be fixed by identifying and isolating the problem, using techniques such as mocking or stubbing.
  • RSpecBisect can help locate the leaky spec causing flakiness.
  • Use RSpecOrderRandom to run tests in random order to identify order-dependent failures.
  • Write tests to validate expected behavior, not just test intermediate results.
  • Consider using string I/O to simplify file handling and reduce dependencies.
  • Run tests in parallel to identify race conditions and dependencies on shared resources.
  • Fixing flaky tests requires patience, persistence, and a methodical approach.