Introduction to the javascript unit test tool QUnit created by the JQuery Team _ jquery

Source: Internet
Author: User
Meta-test, also known as module test, is a test of the correctness of program modules (the smallest unit of software design. Unit Testing is mainly used to test the internal logic of a program, also known as individual testing, structure testing, or logic-driven testing. Generally, the programmer who writes the code is responsible for this. What is unit testing?

Unit Testing, also known as module testing, is a test of the correctness of program modules (the smallest unit of software design. Unit Testing is mainly used to test the internal logic of a program, also known as individual testing, structure testing, or logic-driven testing. Generally, the programmer who writes the code is responsible for this.

Generally, every time a program is modified, a program runs at least one RMB per modification, before and after the authentication program's process, it is likely that you have to perform the billing statement multiple times to verify that the program has passed the authentication Specification (en: Specification) the required job objectives are not smelly; although unit testing is not necessary, it is not bad. This is related to the policy decision of case management.

-- Wikipedia (Chinese and English)

Advantages of Unit Testing

1. It is a verification behavior.
Every function in the program is tested to verify its correctness. It provides a delay for future development. Even after development, we can easily add features or change the program structure without worrying about the damage to important things in this process. It also guarantees code refactoring. In this way, we can improve the program more freely.

2. It is a design behavior.
Writing Unit Tests will let us observe and think from callers. In particular, writing test-first forces us to design programs that are easy to call and testable, which forces us to lift coupling in software.

3. It is a document writing activity.
Unit testing is an invaluable document that best shows how functions or classes are used. This document can be compiled, run, and kept up-to-date, always synchronized with the code.

4. It is regression.
Automated unit tests avoid code regression. After compilation, you can run tests anytime, anywhere.

Refer:

Http://miiceic.org.cn/phrase/200602281036115.html href = "http://miiceic.org.cn/phrase/200602281036115.html" target = _ blank> http://miiceic.org.cn/phrase/200602281036115.html

Http://tech.ddvip.com/2009-06/1245992965124860.html href = "http://tech.ddvip.com/2009-06/1245992965124860.html" target = _ blank> http://tech.ddvip.com/2009-06/1245992965124860.html

Http://www.blogjava.net/square/articles/158103.html href = "http://www.blogjava.net/square/articles/158103.html" target = _ blank> http://www.blogjava.net/square/articles/158103.html

Unit test framework in javscript

  • JsUnit
    The systematic solution is based on XNuit specifications. If you use jUnit, NUnit, and other frameworks, this should be easy to use and include the server side (Java ). Http://www.jsunit.net/
    Rating: comprehensive and professional, suitable for large-scale enterprise-level development.
  • Test. Simple & Test. More
    This is the http://openjsan.org/doc/t/th/theory/Test/Simple/0.21/lib/Test/Simple.html of the testing framework recommended by John Resig, the father of jQuery, in his book "Pro Javascript.
    Rating: it is very easy to use and concise. It is suitable for small and medium-sized projects to quickly introduce unit tests.
  • FireUnit
    John Resig made another task. In his blog, John Resig-FireUnit: JavaScript Unit Testing Extension, he published FireUnit, a Firebug-based Extension developed in partnership with Jan Odvarko.

    In short, FireUnit adds a tag panel to Firebug and provides some simple JavaScript APIs to record and view tests. For more information, see http://shawphy.com/2008/12/fireunit.html.
    Comment: there are traces of Test. Simple. John Resig is a very good guy at learning and innovating. FireUnit has outstanding performance in ease of use and is very suitable for front-end engineers who use Firebug-based debugging environments.

  • QUnit
    QUnit is a JavaScript unit testing tool developed by the jQuery team and can be downloaded from http://docs.jquery.com/QUnit href = "http://docs.jquery.com/QUnit" target = _ blank> http://docs.jquery.com/qunit

    Rating: easy to use and beautiful interface.

Refer:
Http://www.cnblogs.com/kaima/archive/2009/04/09/javascritp_unittest.html

Next we will focus on introducing QUnit

QUnit Introduction

JavaScript still requires good readability, so refactoring is essential. We know that refactoring without unit testing is unreliable, good unit test coverage makes it easier and cheaper to refactor, so it is very important for good javascript programmers to have a unit test framework, QUnit is a powerful and easy-to-use JavaScript testing framework. It is used for testing jQuery and its plug-ins. It can also test common JavaScript code.

Use QUnit

First we first need http://docs.jquery.com/QUnit href = "http://docs.jquery.com/QUnit" target = _ blank> http://docs.jquery.com/qunitto find the qunit.js and qunit.css two files, Qunit framework is as follows:

The Code is as follows:


Http://www.w3.org/TR/html4/loose.dtd>


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.