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