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

Why would you ever sleep in a test?

Not just a dirty hack sometimes

Joel Clermont
Joel Clermont
2025-06-12

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

You might think adding sleep() inside a test is a dirty hack to fix a flaky test, and I would normally agree with you. But as developers love saying... "it depends"

In today's video, I'll show a scenario where it is actually a useful and valid testing strategy.

Watch Now (4 min)

And after watching, don't forget to subscribe to our YouTube channel, so you don't miss future videos.

Here to help,

Joel

P.S. Want to learn how to write effective tests, even in an older untested Laravel app? This is covered in our Laravel testing workshop.

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.