topography linesgreen ellipse
BuildPass logo

Startups: when to write tests?

In the world of startups, when should your team focus on writing tests?

auhtor picture
James Formica
UI focused, builder of silly things
Dec 06, 2021 - 23:37 PMMax 3min read
main image

Developers have a ❤️ love / 💔 hate relationship with tests

Love

  • When they genuinely catch a bug
  • The tidiness of cleanly written test files
  • The satisfying green wall of hundreds of passing tests

Hate

  • Flaky tests that fail the build (usually devs fault though)
  • Messy spaghetti test files doing way too much
  • The feeling of writing tests for the sake of writing tests

Putting this complicated relationship with writing tests aside for a second, let me ask you, when should a startup begin writing tests? I have a feeling people could argue different answers depending on all sorts of factors but here's a few I reckon most will fall into:

  • Straight away. Why are you not writing tests? Write tests!
  • Don't worry about it, tests are for "mature" products, focus on getting your startup off the ground first and being able to pivot quickly
  • Write tests for critical features only to begin with, the core of the product. The rest can be retro fitted later
  • At minimum, write a test for every bug you find to ensure it doesn't happen again

Well let's assume you got an extra marshmallow in your morning hot chocolate from that cute barista, you're in a cheery mood and want to add tests to your code. Well, we haven't even decided what type of tests we should start writing.

Do you start with low hanging fruit and add some simple unit tests for a couple pure functions in a file called helpers.ts ? But how much value is that really going to add? But at least it's a start?

Or how about we go and setup Playwright and get some of our critical work flows tested with E2E tests? Surely that's adding plenty of value! But also likely more complicated to setup and likely to break soon given the speed at which things are changing at our startup 🤔

Now it's time for... an analogy!

Some like to think of tests like private health insurance. When are you comfortable forgoing it and at what point are you not? When we're younger, fitter and healthier it's usually the last thing we think about. We're focused on living, growing, learning. None of our friends are talking about it so how important can it really be? And then time flies by and an unsettling thought creeps into the back of your mind. What IF I have an accident? Will I be alright? Why are my friends not talking about this, I feel like we need to talk about this?

If you've gotten to this point, firstly thank you for taking the time to read this, but if you were hoping for a silver bullet answer that applies to every circumstance then I'm sorry to disappoint.

I genuinely don't think there is one right answer but I would love to hear your thoughts on this. Have you been in a startup? Did they write tests? What tests did they write? Was it time well spent?