Activate your free membership today | Log-in

Wednesday, September 3rd, 2008

QUnit: A simple look at the jQuery unit test framework

Category: JavaScript, Testing, jQuery

Chad Myers has a simple look at GUnit, the jQuery based unit test framework. His article explains how to get going, and walks through a test like this:

JAVASCRIPT:
  1.  
  2. module("Show and Hide");
  3.  
  4. test("should hide the element when hide is called", function(){
  5.  
  6.     $("#testDiv").hide();
  7.  
  8.     // actual, expected
  9.     equals($("#testDiv").css("display"), "none", "The element should be hidden");
  10. });
  11.  
  12. test("should show the element when show is called", function(){
  13.  
  14.     // Arrange
  15.     $("#testDiv").css("display", "none");
  16.    
  17.     // Act
  18.     $("#testDiv").show();
  19.  
  20.     // Assert
  21.     // actual, expected
  22.     equals($("#testDiv").css("display"), "block", "The element should be visible");
  23. });
  24.  

Posted by Dion Almaer at 5:12 am

++++-
4.3 rating from 12 votes

3 Comments »

Comments feed TrackBack URI

There is also jqUnit - a little bit extended version of QUnit, which makes it JSUnit-compatible.

Here is the blog post about my experience with jqUnit:
http://blogs.byte-force.com/xor/archive/2008/03/26/1731.aspx

Comment by xor — September 3, 2008

xor,
.
Which would you choose if you were starting a project today? jqUnit?

Comment by Nosredna — September 3, 2008

I don’t think there is noticeable difference for *new* project. If you don’t have old tests written in JSUnit, then both are the same for you. At the same time, both libraries are not that well documented, so there could be some subtle differences (I didn’t have time to compare code closely).

Comment by xor — September 3, 2008

Leave a comment

You must be logged in to post a comment.