Jsamine Unit Test framework and EXT-JS framework Integration

Source: Internet
Author: User

A recent study of the Jasmine framework has yielded considerable benefits. Based on a company colleague's documentation, here are some of the features of the Jasmine framework.

One: Introduction

The Jasmine Framework is a behavioral-driven development framework for testing JavaScript code that does not rely on any other JavaScript framework, does not require a DOM, and has a very simple and clear syntax.

Second: Scope of application

Because the Jasmine framework does not rely on browsers, DOM, or any JavaScript framework, it is especially suitable for unit test sites, node.js projects, or any project that has JavaScript running.

Small Example 1: For example, to test if the real value is smaller than expected

Beforeeach (function () { 
  this.addmatchers ({ 
     
    tobelessthan:function (expected) { 
      var actual = this.actual; 
      var nottext = This.isnot? "Not": ""; 
     
      This.message = function () {return 
        "expected" + actual + Nottext + "to be less than" + expected; 
      } 
     
      return actual < expected;}}); 

Small Example 2: For example, to test Ajax or other asynchronous behavior:

var klass = function () { 
}; 
     
Klass.asyncmethod = function (callback) { 
  Someasynccall (callback); 
}; 
     
... 
     
It (' should test async call ', function () { 
  Spyon (Klass, ' Asyncmethod '); 
  var callback = Jasmine.createspy (); 
     
  Klass.asyncmethod (callback); 
  Expect (callback). not.tohavebeencalled (); 
     
  var someresponsedata = ' foo '; 
  Klass.asyncmethod.mostrecentcall.args[0] (someresponsedata); 
  Expect (callback). Tohavebeencalledwith (Someresponsedata); 
     
});

Three: Why do we choose the Jasmine Framework?

Although in the market there are many kinds of JS Unit test framework, such as Testswarm, Jstestdriver,buster.js,yui Yeti,sinon, but many unit test framework only support and browser work together, Some unit test frameworks cannot support testing of asynchronous callback code. Some of the code is difficult to understand for the IDE, however, the Jasmine framework is a good framework for the advantages of various frameworks.

Four: The excellent design principle of jasmine framework:

(1) A good JS unit test framework should not be integrated into any browser, framework, platform or host machine language settings.

(2) A good JS unit test framework should be in line with the JS language habits of the grammar.

(3) Good JS Unit test framework should be in any JS can run the place

(4) A Good JS unit test framework should be non-intrusive to the application being tested.

(5) A Good JS unit test framework should be able to integrate well with the IDE, such as through the IDE's static code quality checks.

(6) A good JS unit test framework should be simple enough and easy to get started. I've learned it in 5 minutes, and then I wrote the first demo and ran it.

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.