~/talk

Randomness In Tests (Don't Do It)

Talkat XO Ruby Portland 2025 · on Saturday, 2025-10-11· [testing, ruby]
slides:none on file

Tests that use global randomness cause flakiness: kernel rand and Faker produce nondeterministic values, Postgres ID sequences leak state, and assigning Time.zone mutates a global. Bisect stalls when every test advances the same PRNG. Use deterministic seeds and dependency-injectable PRNGs instead — seed the PRNG per test run, pass Random instances into sample/shuffle, or use FactoryBot sequences. Property-based tools like prop_check or approval testing replace ad hoc sampling. If randomness remains, minimize scope and make it explicit.

AI-written summary · about

  1. 0:00Introduction
  2. 1:03Rewrite tests
  3. 3:30Random test order
  4. 4:58Bad randomness examples
  5. 13:24Trivial vs non-trivial randomness
  6. 13:47Global state and time zones
  7. 15:33Database ID based feature toggling
  8. 16:55Faker for test data
  9. 19:50Bisect and PRNG leakage
  10. 21:54Using Random class
  11. 22:57Best practices
  12. 23:40Shift from Rails
  13. 26:33Critique of Rails
  14. 27:57Migrating Rails apps
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.