QUnit

Last updated
QUnit
Initial release8 May 2008 (2008-05-08)
Stable release
2.24.1 [1]   OOjs UI icon edit-ltr-progressive.svg / 26 January 2025;22 days ago (26 January 2025)
Repository
Written in JavaScript
Type Test automation framework
License MIT
Website qunitjs.com

QUnit is a JavaScript framework for unit testing. Originally developed for testing jQuery, jQuery UI and jQuery Mobile, it is a generic framework for testing any JavaScript code. It supports client-side environments in web browsers, and server-side (e.g. Node.js).

Contents

QUnit's assertion methods follow the CommonJS unit testing specification, which itself was influenced to some degree by QUnit.

History

John Resig originally developed QUnit as part of jQuery. In 2008 it was extracted from the jQuery unit test code to form its project and became known as "QUnit". This allowed others to start using it for writing their unit tests. While the initial version of QUnit used jQuery for interaction with the DOM, a rewrite in 2009 made QUnit completely standalone.

A 2017 analysis of npm and GitHub code repositories showed QUnit was the third most prevalent framework, with half as much usage as the most popular framework, Mocha. [2]

Usage and examples

QUnit uses a set of assertion method to provide semantic meaning in unit tests: [3]

A basic example would be as follows: [4]

QUnit.test('a basic test example',function(assert){varobj={};assert.ok(true,'Boolean true');// passesassert.ok(1,'Number one');// passesassert.ok(false,'Boolean false');// failsobj.start='Hello';obj.end='Ciao';assert.equal(obj.start,'Hello','Opening greet');// passesassert.equal(obj.end,'Goodbye','Closing greet');// fails});

See also

References

  1. "Release 2.24.1". 26 January 2025. Retrieved 26 January 2025.
  2. Fard, Amin Milani; Mesbah, Ali (2017). JavaScript: The (Un)covered Parts (PDF). 10th IEEE International Conference on Software Testing, Verification and Validation (ICST 2017). Tokyo: IEEE.
  3. "Assert methods". QUnit API Documentation. Retrieved 2018-02-14.
  4. "Cookbook: Example test". QUnit API Documentation. Retrieved 2014-06-02.