Saturday, January 19, 2013

JavaScript unit testing using QUnit

In one of the recent hanselminutes, Scott talks to one of the creators of SignalR, a real-time web library ( this episode ). Two things I found really interesting in this talk:

Microsoft allowed the creators to work on their 'garage project' using company resources

SignalR started out as a garage project from two guys at Microsoft, working on it in their own timem. However, after talking to their employer, the project was adopted by Microsoft and now they have a team of 6 or so, helping them on the project. Basically, now their working on their pet project in the boss's time.

SignalR is using Git, TeamCity, BrowserStack, TestSwarm and QUnit

During the podcast, their Continuouse Integration (CI) setup is mentioned. So apparently they use 
  • Git for source control
  • TeamCity for automated building and deployments - find it here: http://ci.signalr.net/
  • Testswarm for coordinating the JavaScript tests
  • QUnit for writing JavaScript unit tests
  • Browserstack for running the tests on all the different browser versions
Pretty cool setup there. Apparently their TeamCity server creates jobs for the Testswarm installation, to run the tests.
But, what I wanted to look into was QUnit for now, so I wrote a few lines to see how this thing works.

QUnit - A JavaScript unit testing framework

Honestly, I haven't tested much of my JavaScript code thusfar. However, There's no reason not to anymore, because QUnit makes it extremely simple.



You don't need to download anything, just get both style and JavaScript files from a CDN. A 'hello world' is quickly written like so:





  
  QUnit Example
  


  
Which will result in the following tests results:


There's no need to talk about this much longer. It works out-of-the box, no prerequisites and very helpful. We'll be using it!

No comments:

Post a Comment