“How do you think when writing tests?” – It’s simpler than you may think

caiozullo

⛩ Caio Zullo

Posted on November 1, 2018

“How do you think when writing tests?” – It’s simpler than you may think

Watch on YouTube

In this episode, we reply to an important question raised by a member of our community.

Question

“I'm trying to understand how you think when writing tests. Do you just try to cover everything that comes to mind or you have some kind of list with priorities? Or you just try to reach max possible coverage?”

Answer

We follow the basics. Our main process is to write the test first, see the test fail (red), then write the minimum amount of code to make the test pass (green), then refactor the code/test *if needed.* By following this process, we end up with pretty high coverage (not always 100% but very close to it). The coverage is not a direct goal. The coverage is more like a positive side effect of following the process.

With that said, it requires discipline and skill to *always* write the test first. You may get stuck in the beginning. We've been doing this for many years, and we still get stuck sometimes! However, the goal is never to be stuck for long. It's wasteful. At the end of the day, shipping is more important than testing first.

When you're stuck, spike some ideas. Go free, without tests (or anything else) in your way. Play with the code (Xcode Playgrounds, Swift REPL, Debugging...) until you're unstuck and found the solution you are happy with. Then think, "now that I know what I want to build, how could I have written the test first?"

When you have the answer, you can discard the spiked solution (commit the spike solution into a separate spike branch), and start fresh, by writing the test first. Next time you have to solve a similar problem, you know how to do it test-first without spiking.

We practice, learn, and get a little bit better every day. The daily practice compounds!

Subscribe now to our Youtube channel and catch free new episodes every week.


We’ve been helping dedicated developers to get from low paying jobs to high tier roles – sometimes in a matter of weeks! To do so, we continuously run and share free market researches on how to improve your skills with Empathy, Integrity, and Economics in mind. If you want to step up in your career, access now our latest research for free.

💖 💪 🙅 🚩
caiozullo
⛩ Caio Zullo

Posted on November 1, 2018

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related