That ‘Aha!’ moment with Unit Testing

I have been reading about unit testing all around me, that its good, its essential, it improves code quality, solidness etc. Well there was no denying really, in fact I was writing unit tests when working mostly with C#. But somehow it wasn’t very organic to my style of development. I mean, it wasn’t one of those involuntary tasks that I do when I am about to start writing code for some feature.

It is a tendency for a developer to first formulate the plan of action in his or her head. Then start executing by writing code. Sometimes I do use a rubber duck to talk through my design steps, sometimes good ol pen and paper works. And then create classes, functions, then refactor, and refactor again … But unit tests I admit, generally followed writing the actual logic. May be that is a crime for purists, but not me. Until I started working on JavaScript. There is a mass migration of UI developers towards JavaScript.


Unless you have been living under a rock, it should be fairly obvious that most of the new projects will have their UI work sketched out in JavaScript, whether you like it or not. Search for it and you should find boat load of material on the good, bad and the ugly (mostly ugly) workings of JavaScript. But one good side effect of such dynamic nature of language is the supreme necessity of tests! I almost feel ominous to use any library that is not provided with strong test cases. The reason being, JavaScript runtime and the whole Web development experience is so forgiving that identifying any issues is delayed until you actually see the error happening. No compilation phase says it all. I admit tools like JSHint, ESLint etc make like easier, but fundamentally it is the developer who has to understand the underpinnings of the language to make it work as he or she intends. And once you do get the language, to make new team members understand whats going in, unit tests go a long way.  I almost feel saint-like when I advocate tests in my team,


Writing tests is one part of it, if you do not do even one of these steps you dont bother writing them in the first place:

  • Keep them fresh and updated
  • Execute them as part of daily build process and do not generate output until all tests are passed
  • A step further, you can also execute them as you write code. (This feels goood!)

So now, when its time for writing a new feature/module in JavaScript here are the steps I follow:

  • Ensure jasmine, karma and gulp is installed. Search for these terms and you should get lots of help for how to setup your development environment with these tools.
  • Turn on the autowatch in karma.conf.js so that as you change code or test files, all tests are executed and the feedback loop is instantly completed.
  • Setup continuous integration to run gulp steps so that on each check in by any team member, these tests are executed on the build server.
  • Oh yes, and now you can write code.

Happy Testing!


vishnu said...

Very excellent blog, You have shared very nice and useful content here, Thanks for sharing your great ideas with us, This blog will help us to enhance knowledge, Thank you so much for providing such wonderful informative article, Keep sharing more informative posts like this.
Now! You can find the best Testing Services in Hyderabad
just visit here:
Software Testing Company in Hyderabad

deepak ladaakhi said...

Thanks for sharing such a nice blog.You can also find OFF PAGE SEO for increase the website ranking.

Free Bookmarking sites,

siyamalhotra said...

I am Shilpa and I just want to tell one thing the masseurs of Delhi Massage Center have done a great job at Massage Center in Delhi I feel very relax after taking Massage in Massage center in Delhi and SPA centers are the best Massage centers in Delhi NCR. Here I got the all the facilities during my massage I have taken Full Body to Body Massage at Delhi Massage Centers I have also taken SPA from the young masseurs I mostly like the CALL IN service when I want to take massage I can visit the massage center in Delhi and then I would like to take massage from my choice masseur. Massage Center in Delhi is very hygienic and clean there I feel like heaven. Once I have taken foot reflexing massage and then I feel very lite and relax.
Delhi Massage Service
Chandigarh massage Services
Hyderabad Massage Services
Mumbai Massage Services
Delhi Night Massage
Body To Body Massage

SARA MARK said...

This is an informative post and it is very useful and knowledgeable. therefore, I would like to thank you for the efforts you have made in writing this article.
Language Translation Services ,
Subtitling Companies in Bangalore

mumbai escorts said...

Hello I am Anupreet Kaur as you have given services to me in Mumbai Escorts Service
I have enjoyed with your Escort Mumbai Call Girls
and she is very hot and sexy and she has given me all kind of services I have taken services in luxury hotels and their waist is very slim and I feel relax after taken services from her. She has good communication skill and their lips are very lusty she is very well educated and I always want to take services from Mumbai Escorts Anupreet Kaur and I want to stay more night and want to spend quality time with her.

Mumbai Escorts
Independent Mumbai Escorts
Independent Escorts in Mumbai
Mumbai Call Girls
Female Mumbai Escorts
Call Girl in Mumbai
Escorts in Mumbai

Post a Comment