“How do you think when writing tests?” – It’s simpler than you may think
Tags: tdd, testing, swift, productivity
Published: 2018-11-01 14:39:54

---
title: “How do you think when writing tests?” – It’s simpler than you may think
published: true
tags: tdd, testing, swift, productivity
canonical_url: https://www.essentialdeveloper.com/articles/how-do-you-think-when-writing-tests-its-simpler-than-you-may-think
cover_image: https://thepracticaldev.s3.amazonaws.com/i/f5y19hni1pwgmulu56sv.png
---

{% youtube 9CyIrbCNWPs %} [Watch on YouTube](https://www.youtube.com/watch?v=9CyIrbCNWPs&list=PLyjgjmI1UzlT2jbk9WeqNrZhZyKpPPaWq)


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](https://www.essentialdeveloper.com/articles/whats-more-essential-for-developers-to-focus-on-result-or-process).  
  
With that said, it requires [discipline and skill](https://www.essentialdeveloper.com/articles/the-importance-of-discipline-for-ios-programmers) to \*always\* write the test first. You may get stuck in the [beginning](https://www.essentialdeveloper.com/articles/junior-ios-developers-can-be-more-productive-than-they-think). 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](https://www.essentialdeveloper.com/articles/number-1-reason-why-you-dont-improve-as-a-software-developer). The daily practice compounds!

[Subscribe now to our Youtube channel](https://www.youtube.com/essentialdeveloper?sub_confirmation=1) 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](https://www.essentialdeveloper.com/courses/career-and-market-strategy-for-professional-ios-developers).