QUnit

“I’m surprised how little code this needs” — @scott_gonzalez

some detail (and links) to the qunit tests Scott created

QUnit—quick to write, quick to run!

  1. Include qunit.js and qunit.css
    <link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-git.css">
    <script src="http://code.jquery.com/qunit/qunit-git.js"></script>
    		
  2. Include the qunit HTML
    <h1 id="qunit-header">QUnit example</h1>
    <h2 id="qunit-banner"></h2>
    <div id="qunit-testrunner-toolbar"></div>
    <h2 id="qunit-userAgent"></h2>
    <ol id="qunit-tests"></ol>
    <div id="qunit-fixture">test markup, will be hidden</div>
    		
  3. Write a test
    test( "a basic test example", function() {
        ok( true, "this test is fine" );
        var actualValue = "hello";
        equal( actualValue, "hello", "We expect value to be hello" );
    });
    		

QUnit example

    test markup, will be hidden

    About

    QUnit is a powerful, easy-to-use, JavaScript test suite. It’s used by the jQuery project to test its code and plugins but is capable of testing any generic JavaScript code (and even capable of testing JavaScript code on the server-side).

    QUnit is especially useful for regression testing: Whenever a bug is reported, write a test that asserts the existence of that particular bug. Then fix it and commit both. Every time you work on the code again, run the tests. If the bug comes up again—a regression—you’ll spot it immediately and know how to fix it, because you know what code you just changed.

    Having good unit test coverage makes safe refactoring easy and cheap. You can run the tests after each small refactoring step and always know what change broke something.

    QUnit is similar to other unit testing frameworks like JUnit, but makes use of the features JavaScript provides and helps with testing code in the browser—for example, with it’s stop/start facilities for testing asynchronous code.

    Contact

    QUnit is maintained by Jörn Zaefferer.

    Please post to the QUnit and testing forum for anything related to QUnit or testing in general.

    What’s happening? Check the Testing Team planning wiki.