No Compromises · Joel Clermont and Aaron Saray
Do you ever finish writing a test and wonder if it is actually proving anything about your code or just confirming that Laravel works? In the latest episode of the No Compromises podcast, we discuss how to tell the difference between tests that validate your logic and tests that merely exercise the framework. We share a practical gut check: if you cannot make a test fail by changing something in your own application code, it probably should not be in your test suite. We also look at this idea from the other direction, asking whether the code being tested is something we actually wrote. We also dig into why testing validation rules is worth the effort even when they feel boilerplate, how feature versus unit test style shapes these decisions, and why the real goal is simply getting to a place where your tests help you ask the right questions. Join the Mastering Laravel community at https://masteringlaravel.io/community 00:00 Are we testing code or framework 02:00 Joel metric for framework-only tests 05:15 Bottom-up testing perspective by test type 07:36 Why validation rules still deserve tests 10:40 Silly bit
0:00JoelWelcome to No Compromises. A peek into the mind of two old web devs who have seen some things. This is Joel.
0:08AaronAnd this is Aaron.
0:16JoelI talk a lot about testing. It's kind of one of my pet topics. And, as with anything, like we do, I want to make sure the thing I'm doing has value.
0:27Like, it's giving me what I think it's giving me, right? So, with testing, one of the things I've heard some pushback on, or some... no, debate's too strong a word. But like some questioning is, how do you know if you're writing a test that's actually testing your code, your logic?
0:46Versus, maybe you're writing all these unnecessary tests that are testing what Livewire or Laravel, you know, the framework, is doing for you? Like, it should have its own test, right? So, have you heard this? Let me just throw that out there. Have you heard this kind of debate or discussion?
0:56AaronYeah. There's a lot of discussion on where the boundary of where tests are. Like, am I testing just my logic? If I'm testing, let's just say I have a service class. Should I just test a service class?
1:12Because I can assume that a controller I wrote works because it's Laravel? Well, maybe that's not the right place, maybe you have to test end-to-end. And then there's other things where people have tested things like the rules or custom messages.
1:24Not running validation, but just testing the values. Like, is that testing that's technically testing your code, but if you're running it through the framework, isn't it testing that the framework interpreted that stuff, right? And should they have already been tested? So, yeah, there's a lot of questions on where the boundaries lie.
1:40JoelYeah. And some of the ones you mentioned are great examples. Because I think they are a little fuzzy. Like, there are some of those tests that we write where I could take an objective step back and be like, "Yeah. I mean, this is testing framework behavior."
1:53So, here's how I think about it. I want to share kind of my metric on, am I testing the framework? And what I mean by that is like, is this test valuable?
2:02AaronOkay.
2:05JoelLike, should it exist in my test suite? Because that's ultimately what we're trying to answer. It's not just a-
2:09AaronAnd I want to make sure we just define the word valuable because we're making an assumption that the Laravel code is fully tested, which we know it is.
2:17JoelYes.
2:19AaronBut when you say valuable, there's a question of like, "Well, if I'm testing the framework, the whole product is mine regardless if it has a framework inside of it or if it's my code."