JavaScript Unit Testing - the WHY

July 08, 2013

When i say ‘javascript testing’ what i mean is ‘automated javascript testing’.

I love writing javascript apps. But for a long time i never felt the need to write tests for my javascript code. My testing consisted of continually refreshing the browser window. Now as i went back to those apps to make enhancements or fix bugs, i started to feel really uncomfortable. Everything seemed very tedious. I couldn’t lay my finger on what the problem was for quite some time. And then it hit me - bam! I was irritated by the continuous manual testing i had to go through each time.

You might think that i was a bit naive to have recognised the problem, but that’s ok. The important thing is i did realize the problem. And now i am trying to fix it.

Let me list down the why’s in a list because i know that’s how you like it.

If you like programming, automating anything will make you happy. I can’t stress it enough. A happy programmer is a more productive programmer. For me, this is the most important reason to write tests. Writing tests makes you write better code. And the only way to come to terms with this fact is by trying it yourself. Write some code without test. Now redo the exercise by first writing a test first. See the difference? No? Then maybe go back to the first point. Research shows that writing tests for your code reduces bugs. We don’t like bugs, do we? Except while taking macro photographs. If you are working in a team, answering why to write tests is a no brainer. Hope the above reasons convince you that writing tests is good.

Good, if you are convinced we will move on to the next phase. The HOW. The how part for javascript is actually trickier than other languages. But that is for the next article to discuss.

The article on Javascript Testing - the HOW (part 1) is up.

Happy testing!

Mukesh Soni

Written by Mukesh Soni. Now looking for a frontend gig. Good at JavaScript, reactjs and family. Knows and has worked in nodejs. Been doing this stuff for 7 years (since 2011).

Also getting into react-native of late and loving it. `react-native` might be the future of mobile development.

Loves functional programming. Knows a little bit of purescript, haskell and elm. You can ask me about functors 😜.

Follow me on TwitterLook at my open source work on github