Setup and Teardown for QUnit Tests

The QUnit documentation talks about how to define setup and teardown methods, but fails to give a code example. Here is a quick one for reference:

module("Module Name", {
	setup: function() {
		// setup logic here
	},
	teardown: function() {
		// teardown logic here
	}
});

test("Some Test", function () {
	ok(true, "test code here");
});

Setup and teardown functions are defined on a per-module basis, via the “lifecycle” object. This object just has methods “setup” and “teardown” as shown above. Pretty simple.

  1. Might want to mention that the module pertains to all the tests directly below it until another module is defined.
    -module1
    -test1
    -test2
    -module2
    -test3
    -test4

  2. Haha nevermind I suppose you don’t need to mention it considering it’s in the documentation you linked. Any who here is a pretty good QUnit tutorial site. http://benalman.com/talks/unit-testing-qunit.html Also, is the same() function just a depreciated version of deepEqual() function http://docs.jquery.com/index.php?title=QUnit/same&redirect=no ?

Leave a Comment


NOTE - You can 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>