Unit testing JavaScript

I am well used to writing unit tests for java code (although most project managers don't really go for it), but had not come across something decent to do this for JavaScript. QUnit appears to be just the job. I don't think it is just me, but I seem to write pretty badly structured js. Coming from java this architectural stuff is mostly forced on you, but not in js. However once you start to write unit tests for your code you start to think about laying this all out better.
I read through the intro.
Then I read this simplified getting started.
And then I wrote some tests for my own code. Altogether this took me just over an hour. A worthwhile investment. This was of course the point where I realised that my code was not particularly testable. Ah well, I will refactor it from now on with this purpose in mind.
Next off I am going to go through the cookbook as it seems to address some of the issues that I want cleared up before I commit fully to this - things like manipulating the DOM.
Once I have some basic tests running I think I will give grunt.js a spin and see if this is a more practical way to launch and manage these tasks.

Comments

Popular posts from this blog

Building a choropleth map for Irish agricultural data

Early Stopping with Keras

AutoCompleteTextView backed with data from SQLite in Android