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.

migration

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,

god

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!

Abhang Rane


8 comments :

Reader's Comments

  1. Hi Guys! Manvi Kakkar offers reliable and safe Mumbai Escorts at reasonable rates. She is a high profile Mumbai Independent call girls, Escorts services in Mumbai and Get the quality oriented and the best Mumbai escorts agency from Manvi Kakkar waiting just for you to offer extreme pleasure.



    Manvikakkar

    Mumbai Independent Escorts Services

    Mumbai Escort

    Mumbai Escorts

    Escorts in Mumbai

    call girls in Mumbai

    High Profile Escorts in Mumbai

    High Profile Female Escorts in Mumbai

    Mumbai Escorts Services

    Independent escorts in Mumbai

    Escorts Service in Mumbai

    Mumbai Call Girls

    ReplyDelete
  2. "Enhance your career with expert salesforce development training designed for beginners and professionals alike. Gain hands-on experience and master Salesforce platform skills to drive real-world business solutions."

    ReplyDelete
  3. Learn core Java programming concepts to build secure, scalable, and high-performance applications. java full stack course

    ReplyDelete
  4. Learn to design user-friendly and visually ui ux design course
    appealing digital products by focusing on user experience and interface design.

    ReplyDelete
  5. Learn how to structure and organize data modeling course
    data efficiently using models that support accurate analysis and decision-making.

    ReplyDelete
  6. This comment has been removed by the author.

    ReplyDelete
  7. Learn how to access and manage digital land records through the Bhoomi land information system.dell boomi course

    ReplyDelete