Javascript testing framework Qunit

Source: Internet
Author: User

We all know that java has a testing framework called Junit, which can be used to perform unit tests with simple code. Recently, jquery has developed a javascript testing framework called Qunit. The following is an introduction to QUnit on the official jquery website. I hope it will help you.

 

 

Introduction

It is very basic to use automated software testing tools in software development. Unit testing is the basic content of Automatic Testing: for unit testing of your function, it is best to write it only once, and everyone who uses your function can run your test, however, there is no need to communicate with each other or do additional work.

 

Another advantage of testing is that testing can drive the development of software, that is, "test-driven development". First, write a simple test, and then write the implementation code for the test, then add the test content. to implement it, the code written by repeating this process step by step is often better than the code written directly.

 

Js unit testing is no different from other languages. A testing framework is required to write a real test.

 

Automated Unit Testing

 

Problem

Because you have benefited from TDD, you may want to automatically test your application and write your own test program, but it involves a lot of work (including compatibility with different browsers)

 

Solution

In some js unit testing frameworks, you have decided to choose QUnit. Qunit is a unit testing framework implemented by jquery and is widely used.

 

Displays test results.

 

 

   <Script src =/resources/qunit. js> </script> <script> test (a basic test example, function () {var value = hello; equal (value, hello, we recommend CT value to be hello) ;}); </script> 


 

Open in the browser and the result is as follows:

 

The most important tag in html is

The test result of Qunit in the element is added to this label. The Test method comes from qunit. the js file contains two parameters. The first one is a string, indicating the name of the test, which is displayed in the test result to distinguish the test result, and the last one is a function, function contains the code to be executed for the test, including one or more assertion. Here the equal method is used to display the test result.

 

If you want to see the effect in your browser, you can download this demo.

 

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.