In one of our projects we are experiencing random failures of tests, when re-running them more often than not they succeed again.
We're using Laravel 5.8, with phpunit for tests, and in our tests we often seed the database using factories and Faker.
So I was wondering, is it possible to, at the end of the tests (especially when they fail), to print the seed used by Faker to generate the values? So I could then set this seed before running the tests, so I can reproduce the errors?
After some more checking I found that faker uses
mt_rand
internally.So what I did, was set the seed at the start of each test in
setUp
and then print it intearDown
:Then it will print the seed of each failed test, and to reproduce while debugging simply replace
$this->seed = rand();
with$this->seed = the seed;
.