Consistent test organization

I like patterns

Joel Clermont
Joel Clermont
2024-02-21

I very much rely on patterns in my code.

One example is how individual test methods are ordered within a Feature test. At a high level, the controller methods are tested in the same order as the default resourceful controller order: index, create, store, show, edit, update, destroy.

Then, within each controller method group, the individual tests follow a consistent order as well: authentication, authorization, the success path, and finally other failures like "not found", validation logic, and so on.

It makes it super easy to jump into an old project, or to see I'm missing something when scanning. As a side benefit, if you use any tools like GitHub Copilot, I've found they pick up on this structure and suggest scaffolding out tests more precisely.

Here to help,

Joel

P.S. Want to get better at testing? Let's pair for an hour and I can help you out.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼

Level up your Laravel skills!

Each 2-minute email has real-world advice you can use.