QUnit

QUnit
Stable release
1.20.0 / 27 October 2015 (2015-10-27)
Written in JavaScript
Type Test automation framework
License MIT
Website qunitjs.com

QUnit is a JavaScript unit testing framework. While heavily used by the jQuery Project for testing jQuery, jQuery UI and jQuery Mobile, it is a generic framework to test any JavaScript code. It supports server-side (e.g. node.js) and client-side environments.

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

History

QUnit was originally developed by John Resig as part of jQuery. In 2008 it was extracted from the jQuery unit test source code to form its own 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.

Usage and examples

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

A basic example would be as follows:[2]

QUnit.test('a basic test example', function (assert) {
  var obj = {};

  assert.ok(true, 'Boolean true');       // passes
  assert.ok(1, 'Number one');            // passes
  assert.ok(false, 'Boolean false');     // fails

  obj.start = 'Hello';
  obj.end = 'Ciao';
  assert.equal(obj.start, 'Hello', 'Opening greet'); // passes
  assert.equal(obj.end, 'Goodbye', 'Closing greet'); // fails
});

See also

References

  1. "Assert methods". QUnit API Documentation. Retrieved 2014-06-02.
  2. "Cookbook: Example test". QUnit API Documentation. Retrieved 2014-06-02.
This article is issued from Wikipedia - version of the 8/1/2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.