Karma+jasmine Automated Testing

Source: Internet
Author: User

1. Install Nodejs and enter the project directory

2. Installing Karma and related plugins

NPM Install Karma--save-dev

NPM Install Karma-jasmine karma-chrome-launcher--save-dev

NPM install-g KARMA-CLI

3. Execute Karma Start, you can see Karma will open the browser automatically

4. Enter./node_modules/karma/bin, execute Karma INIT, and successfully configure the Karma Automation run script

5. Modify the Karma.conf.js configuration file

Module.exports = function (config) {  config.set ({    basepath: '). /.. /.. /',    frameworks: [' Jasmine '],    files: [' *.js '],    exclude: [' karma.conf.js '],    reporters: [' Progress ', ' Coverage '],    preprocessors: {' src.js ': ' Coverage '},    coveragereporter: {      type: ' html ',      dir: ' Coverage /'    },    port:9876,    colors:true,    loglevel:config. Log_info,    autowatch:true,    browsers: [' Chrome '],    capturetimeout:60000,    Singlerun:false,    concurrency:infinity  })}

6. New Test.js

Describe ("A suite of basic Functions", function () {
It ("ABCD", function () {
Expect ("DCBA"). Toequal (Reverse ("ABCD"));
});
It ("Array", function () {
Expect (["Red", "green"]). Toequal (Slice (["Red", "green", "blue"]);
});
});

7. New Src.js


function reverse (name) {
Return Name.split (""). Reverse (). Join ("");
}
function slice (name) {
Return Name.slice (0,2);
}

8. Start Karma test, Karma start karma.conf.js

9. Install the Code Coverage plugin KARMA-COVERAGE,NPM install Karma-coverage

10. Start Karma Start, locate the index.html file under the project directory, coverage/chrome/index.html Open, we see the Code Test overlay Rate Report

Other questions:

environment variable Problem of 1.chrome_bin

Setup method: Find the installation location of CHROME in the system, find Chrome.exe file ~ D:\workspace\javascript\karma>set chrome_bin= "C:\Program files (x86) \ Google\chrome\application\chrome.exe "http://www.blogjava.net/qileilove/archive/2014/02/18/409973.html

http://www.haomou.net/2015/03/10/2015_karma_jasmine/

Karma+jasmine Automated Testing

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.