Wednesday, September 3rd, 2008
QUnit: A simple look at the jQuery unit test framework
![]()
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:
-
-
module("Show and Hide");
-
-
test("should hide the element when hide is called", function(){
-
-
$("#testDiv").hide();
-
-
// actual, expected
-
equals($("#testDiv").css("display"), "none", "The element should be hidden");
-
});
-
-
test("should show the element when show is called", function(){
-
-
// Arrange
-
$("#testDiv").css("display", "none");
-
-
// Act
-
$("#testDiv").show();
-
-
// Assert
-
// actual, expected
-
equals($("#testDiv").css("display"), "block", "The element should be visible");
-
});
-





4.3 rating from 12 votes







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
xor,
.
Which would you choose if you were starting a project today? jqUnit?
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).