logo
podcast Podcast
get help Get Unstuck

What makes a test valuable

It's not a metric like coverage

Joel Clermont
Joel Clermont
2024-08-09

Sometimes, I will see a really detailed test, but when I look closer, I see it is actually testing internal framework behavior. I don't find those kind of tests valuable. Laravel already has its own test suite.

For a test to be valuable to me, I have a simple heuristic in mind: I should be able to make the test fail by changing one line of application code or configuration.

If I can't do that, I'm probably just testing the framework, and I can delete the test.

For example, maybe except for compliance reasons, there's no need to write a test to prove that Laravel will return a 404 if you pass it a route with an ID that doesn't exist.

On the other hand, if you're doing any sort of explicit route model binding, custom binding resolution, scoping, changing the default key, or things along those lines, then those NotFound tests are useful.

It can be a blurry line sometimes, but I find this heuristic helps me keep my test suite focused on the application logic.

Here to help,

Joel

P.S. Want to ask me any sort of Laravel question you can imagine? I love answering, but even better, you can ask that question to a whole group of Laravel developers in our community.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice you can use.