QUnit: A JavaScript Unit Testing framework.

What is QUnit?

QUnit is a powerful, easy-to-use JavaScript unit test suite. It's used by the jQuery, jQuery UI and jQuery Mobile projects and is capable of testing any generic JavaScript code, including itself!

Getting Started

A minimal QUnit test setup:
1
2
3
4
5
6
7
8
9
10
11
12
13
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>QUnit Example</title>
  <link rel="stylesheet" class="/resources/qunit.css">
</head>
<body>
  <div id="qunit"></div>
  <script src="/img/spacer.gif"> script>
  <script src="/img/spacer.gif"> script>
</body>
</html>
The contents of tests.js:
1
2
3
test( "hello test", function() {
  ok( 1 == "1", "Passed!" );
});

The result:

Download

QUnit is available from the jQuery CDN hosted by Media Temple.

Current Release - v1.10.0

  • qunit-1.10.0.js
  • qunit-1.10.0.css
  • Changelog
  • via npm

To test the latest features and bug fixes to QUnit, a version automatically generated from the latest commit to the QUnit Git repository is also available for use.

  • qunit-git.js
  • qunit-git.css

Get Involved

  • Check out the API documentation or the Cookbook to learn how to use QUnit
  • To see more examples, check out the unit tests of jQuery, jQuery UI or the jQuery Validation Plugin.
  • The code is located at: github.com/jquery/qunit.
  • Planning for QUnit and other testing tools also happens on the on the jQuery Testing Team planning wiki.
  • Please post to the QUnit and testing forum for anything related to QUnit or testing in general.
  • For announcements, follow @qunitjs

History

QUnit was originally developed by John Resig as part of jQuery. In 2008 it got its own home, name and API documentation, allowing others to use it for their unit testing as well. At the time it still depended on jQuery. A rewrite in 2009 fixed that, and now QUnit runs completely standalone.

QUnit's assertion methods follow the CommonJS Unit Testing specification, which was to some degree influenced by QUnit.