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.
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!)
- 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.