Getting started with Unit Testing JavaScript using QUnit

It is good to have automated unit tests for the codes while developing. In unit test we test smallest unit of the code for a particular behaviour. The Unit test helps us to find bugs in the code early in the development cycle. Essentially unit test is the piece of code which verifies behaviour of a particular unit of the code in the development phase. Unit tests can be run by the test runner multiple times to verify behaviour of a particular unit of code for different set of input. Now a day’s most of the application development are adhering to Agile and TDD approach. In the test driven development approach, first you write a unit test, it will fail, then write application code to pass the test. Unit testing is not different in JavaScript than other programming languages. To do unit testing or TDD in JavaScript, you need a testing framework. There are many popular JavaScript testing framework available. Some of them are as follows:

  • · Mocha
  • · Jasmine
  • · QUnit
  • · JSUnit

In this article we will focus on QUnit. QUnit is a unit testing framework provided by the jQuery team. It provides a rich set of test assertions, highly informative test suite UI, support of synchronous and asynchronous call back, support of test module etc. In this post we will cover the following topics,

  • Write first unit test
  • Understating the test suite UI
  • A look into the assertions
  • Grouping the tests

Writing the first test

Let us start with setting up the QUnit for the JavaScript unit testing. You need to add reference of the two QUnit files on the HTML page. Either you can have files locally in the project or you can use the reference of the jQuery CDN. I am going to use the CDN option as shows below:

Read full article here on Infragistics blog

Discount for my blog readers for video tutorial on WatchMeCode


Many of you have asked me recently that how I learn JavaScript and other related stuff. One of the resource, I heavily rely and learn from is WatchMeCode videos by Derick Bailey. I watch videos published here. Clearly videos demonstrate deep understanding of Derick on the subject and certainly you will be benefited by his teaching.

About WatchMeCode

WatchMeCode is a video tutorial site by Derick. He publishes various episodes here. You can find videos on following topics to learn.


As of now there are total 60 episodes and counting. Out of 60, few episodes are free to watch. There are episodes on JavaScript, Node, MongoDB etc. I am sure these episodes from none other than Derick will add lot of values to your learning and in your projects.

Find all episodes here

About Derick Bailey

Derick is a popular author, blogger and JavaScript lover. He blogs at and you can follow his tweets at .

How I can help to get subscription?

WatchMeCode monthly subscription is of $ 14 (roughly 840 RS. Per month). I can help you in getting the subscription in $9(roughly less than 500 RS. Per month). To get the discount coupon send me a mail on debugmode[at]outlook[dot] com or tweet me at

I would say WatchMeCode worth much more than 500 RS and you must transact 500 RS per month to learn from one of the best in our industry.