QUnit

from Wikipedia, the free encyclopedia
QUnit

Example for QUnit test.png
Result of a QUnit test
Basic data

developer jQuery Foundation
Current  version 1.22.0
(February 23, 2016)
operating system platform independent
programming language JavaScript
category Module test
License MIT license
German speaking No
qunitjs.com

QUnit is a free module test framework for JavaScript that is especially suitable for unit tests . It was originally developed for software testing for jQuery . The first version was published in 2008 and has since been maintained and developed by the jQuery team.

history

Originally, John Resig developed the framework without a name as a test framework for jQuery. In 2008 he separated the code and published it under the name QUnit so that other projects could also use the framework for tests. Since reprogramming in 2009, QUnit can be used completely independently of jQuery.

concept

QUnit adopts the concept of the XUnit framework. The tests are divided into individual modules, which can consist of one or more tests, which in turn contain the individual assertions . Asynchronous tests can be used to test Ajax and other applications that work via callback functions .

example

The following example consists of a single module with only one test that wurzeltests a function designed to calculate the square root of a real number.

QUnit.module( 'Beispielmodul' );
QUnit.test( 'Test für wurzel', function( assert ) {
    assert.expect( 3 ); // Anzahl der Assertions
	assert.ok( wurzel( 2 ) < 1.5, 'Wurzel aus 2 ist weniger als 1.5' );
	assert.equal( wurzel( 9 ), 3, 'Wurzel aus 9 ist 3' );
	assert.throws( function() {
		wurzel( -1 );
	}, 'Wurzel einer negativen Zahl erzeugt Fehler' );
} );

application

QUnit tests, both in a web browser in browser without JavaScript environments such as Node.js be performed.

For tests in the browser, an HTML document is created that contains a small basic structure into which QUnit enters the results and which integrates QUnit, the code to be tested and the test as JavaScript files. QUnit then runs all the tests that are included and displays the results.

For tests without a browser, the programmer has to start QUnit himself and output the results in a suitable form, with ready-made scripts that carry out the necessary steps available for most environments.

The test results can also be passed on to continuous integration systems such as Jenkins .

QUnit can be expanded with various plugins. There are plugins that add new assertions ( e.g. to test individual pixels of a canvas element ), to provide mock objects ( e.g. to simulate the server component when working with XMLHttpRequest ) or to determine the test coverage .

commitment

In a survey from 2009, QUnit was one of the most frequently used test frameworks for JavaScript with around 20%. In addition to jQuery and jQuery UI , a number of other well-known software projects use QUnit to test their JavaScript components, such as WordPress , MediaWiki or Bootstrap . QUnit was used in BrowserSwarm and the Mozilla tutorial for creating web apps also recommends QUnit for testing.

literature

  • Dmitry Sheiko: Instant Testing with QUnit. Packt Publishing, 2013. ISBN 978-1-78328-218-0 .
  • Frank Bongers, Maximilian Vollendorf: jQuery: The practical book. Galileo Computing, 3rd edition 2014. ISBN 978-3-8362-2638-7 . Chapter 11: QUnit - Testing with jQuery.

Individual evidence

  1. qunit-npm-Package , accessed on November 6, 2014
  2. a b Plugins on qunitjs.com, accessed on November 6, 2014
  3. John Resig, Bear Bibeault: Secrets of the JavaScript Ninja. Manning, 2013. ISBN 978-1-933988-69-6 . P. 20.
  4. Aaron Jorbin: JavaScript Unit Tests for Core. make.wordpress.org, published September 13, 2013, accessed November 6, 2014
  5. Manual: JavaScript unit testing on mediawiki.org, accessed on November 6, 2014
  6. bootstrap / js / tests on GitHub, accessed November 6, 2014
  7. Alexander Neumann: BrowserSwarm: Test JavaScript applications across browsers and devices. Published September 27, 2013, accessed November 6, 2014
  8. Your first app on the Mozilla Developer Network, accessed November 6, 2014

Web links