Unit testing jQuery plugins with jqunit

Whilst creating a plugin for jquery, that would provide auto formatting for a textbox for numeric values, I was looking for a way to run the tests for confirm its functionality. After getting sick of running the tests manually the penny dropped that I could unit test the plugins functionality. After a little searching I came across jqunit that seems to fit the bill perfectly.

The project is hosted over at google code. The tests them self run from a html file but the a template is provided with the jqunit library. The tests are simple to create and follow the jquery syntax style. Below is a smple test case with unit test

var numericTestCase = new jqUnit.TestCase('jQuery.numeric - decimal',function(){
 /*setup*/

  },function(){

    /*teardown*/

});
numericTestCase.test('T1: Null Value ',function(){
    var txtInput = $("
");
    txtInput.numeric(true);
    txtInput.blur();

    jqUnit.equals(txtInput.val(),"0.00");
});

Tests can quickly be written to test the functionality of your code. With the testing being able to run form a single location it provides a quick an easy way to check your plugins work across multiple browsers, that is, as long as you have written the correct tests.

Related Posts:

This entry was posted in Development Log and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>