In partnership with

I hate testing.

It feels like a complete waste of time, doesn’t it? Why would I write a test when I can spend that time actually writing code?

One day I was in an interview. The interviewer asks, “So what’s your approach for testing?”

I panicked. I’ve never really done it before. What am I supposed to say?

I tried to recite everything I’d learned from random YouTube videos.

The interviewer saw right through it and looked at me like a lost cause.

pathetic dot jpg

That was brutal.

So, I decided to try testing in a new project.

Writing my first test feels exactly like writing my first ever program (It wasn't exactly the first, but probably the first time I persisted for more than 5 minutes)

I have no idea what to do.

So I did a little bit of research.

Apparently, there are three steps

  1. Plan what you are going to implement. Write a test for that. The test should first fail because you haven't written the implementation.

  2. Write code that passes the test

  3. Refactor to improve the code

red green blue tdd

It was not fun, but I managed to get it done.

It definitely feels like it slows me down.

But then something magical happens. My code doesn’t break when I add new stuff (at least not as often).

It happens for 3 reasons:

  1. The test is constantly running. If something breaks, I know immediately I messed up something

  2. This TDD approach forced me to think about cases that could make the program fail. So I write code to defend those cases.

  3. It also forces me to think about what I actually want to implement instead of just winging it.

After that, I realized that writing tests isn’t something optional or gimmicky.

I would go as far as saying it might be one of the most important factor that determines code quality.

With that said, I still hate it.

But I probably won’t stop learning how to do it.

- Fee from Anime Coders

PS: I want to share topics I'm excited about while making sure you enjoy reading them. Drop a quick reply below to let me know what you think about this email.

Keep Reading