logo
podcast Podcast
get help Get Unstuck

Start with the simple test

You don't have to test everything at once

Joel Clermont
Joel Clermont
2024-08-23

When testing the "happy path" of a new feature, it's tempting to write a test that covers every possible piece of data.

Instead, I've found benefit in starting with the simplest version of the test and creating additional test methods to cover more complicated scenarios.

For example, if you're testing an index method, I like to have the simple test be one where there are no records. Not only is it easy to write and build momentum on the feature, but it also helps ensure that the controller is handling the empty state correctly.

Then, I'll add a test where there is one record, and then another where there are multiple records.

Or if you're testing a store method, have the simple test be one that only specifies the minimal set of required fields. Then, other tests can add in the optional fields.

Not only does this make writing the tests easier, it makes the test suite clearer to read and understand.

Here to help,

Joel

P.S. A lot of my tips are on testing. Why? Tests save me so much time and frustration, I can't imagine living without them. Want help getting started?

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.