Hate Unit Tests??? Me tooo…

Okay so where do I start? hmm…Well, what does unit testing do? Improve software quality, improve design, reduce the cost of change and most of all makes you slow down and think. We all(most developers)hate them, at least I know I do. Why do we have to write unit tests to test our code when we have the testers who are going to test it anyway for different set of users, different browsers, different mobile devices, different operating systems blah blah blah (God bless their souls), you think coding is difficult, testing is a pain in the you know where (kudos to all the testers out there, I wouldn’t want to switch roles with you EVER!).… so why bother with unit tests?

You have made an awesome reusable component which meets all your requirements and a couple of weeks later some developer decides to change your component to make it work for his use case and that’s all he cares about (****). Then a couple of months later an actual defect gets assigned to you saying that your component never worked for YOUR use case. Then what are you going to do? Split your head to two halves and start debugging from scratch? Dive into all the git commits to see who messed it up and try to fix all cases?Hell no! That is when unit tests will save your ass from near future brain death.

Obviously his requirements are totally different or an addition to your requirements so, why not make another component which is similar except for one thing ? Boo ! wrong approach. Get your shit together and write your unit tests for your components. So, when the other developer makes changes to your component it breaks your tests forcing him to fix it. yaaay!

I personally hated unit tests but there is no escape from it or you should chose not to escape. So, I finally got a cup of green tea and went through a bunch of existing unit tests then I realized that its actually not that bad. It forced me to think like a browser (in my case as I’m an AngularJS developer) — what is it that I want my component to do? what should it do when this happens? Am I looking at the requirements right? Is this the only best solution I can think of? How can I generalize and optimize this solution if someone else wants to use it? Error handling? Is it setting the right values? and more and more questions kept popping up which usually don’t come to my mind when I’m just coding the solution. It helps you understand your code in and out and also the loopholes. Now, I realize how important unit tests are and you should too!!! Unit tests eh?? I’m ready!

Show your support

Clapping shows how much you appreciated Nikki’s story.