karma测试环境搭建及配置

1、在你的项目中全局安装karma;npm install -g karma;

2、进入你的测试脚本上一级,如:


karma测试环境搭建及配置_第1张图片

在命令行中输入karma init;出现如下的内容:


karma测试环境搭建及配置_第2张图片

填写你需要的配置信息,也可以生成后在文件中进行修改。配置内容的具体含义如下:

D:\workspace\javascript\karma>karma init

Which testing framework do you want to use ?

Press tab to list possible options. Enter to move to the next question.

> jasmine

注:测试框架选择

Do you want to use Require.js ?

This will add Require.js plugin.

Press tab to list possible options. Enter to move to the next question.

> yes

注:需不需要引入requirejs

引入requirejs的原因:加载相互依赖的js文件

Do you want to capture a browser automatically ?

Press tab to list possible options. Enter empty string to move to the next question.

> Chrome

>

注:选择打开的浏览器

What is the location of your source and test files ?

You can use glob patterns, eg. "js/*.js" or "test/**/*Spec.js".

Enter empty string to move to the next question.

>

注:karma启动时加载的目标文件和测试文件

Should any of the files included by the previous patterns be excluded ?

You can use glob patterns, eg. "**/*.swp".

Enter empty string to move to the next question.

>

注:加载的目标文件不需要测试的文件

Do you want Karma to watch all the files and run the tests on change ?

Press tab to list possible options.

> yes

注:karma要不要动态监听目标文件和测试用例变化

Config file generated at "D:\workspace\javascript\karma\karma.conf.js".

这个指令跑完后你就会发现目录底下多了个配置文件karma.conf.js,test-main.js

karma.conf.js:  karma配置文件

test-main.js:    requireJS配置文件


karma.conf.js中files是配置重点:

karma测试环境搭建及配置_第3张图片

你可能感兴趣的:(karma测试环境搭建及配置)