Black Friday: the Laravel testing course is $149 instead of $249, through Dec 7. See the course →
logo

Picking a good test value

And avoid flaky tests

Joel Clermont
Joel Clermont
2024-02-23

From our daily Laravel tips email. Get the next one in your inbox.

This is a lesson I learned the hard way: Be careful when picking test values to make sure they can't collide with random faker data.

For example, if you're testing a wild card search against a few fields, don't use "ok" as your test value. Why not? Well, Faker can generate a random name that could potentially match, like "Brooks".

When this happens, your test will randomly fail, but then pass if you run it again. It might only happen one out of 500 test runs. Flaky tests are so frustrating!

Choosing a slightly more complex value like "search-term" can save you grief later.

Here to help,

Joel

P.S. Did you know we have a "pay what you want" book of security tips for your Laravel app?

Want a tip like this in your inbox every weekday?

Each one takes less than 2 minutes to read. Join 4,000+ Laravel developers who already get them.

email
No spam. Only real-world advice.
Toss a coin in the jar if you found this helpful.