karma测试环境搭建及配置

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

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


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


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

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是配置重点:

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,494评论 0 23
  • 日日是好日 文/洪平 江南的春天多雨,刚过清明,雨水一直不停歇,白天下夜里下,下得累了,停会接着下。 江南的雨是闷...
    洪门三少阅读 2,990评论 0 0
  • " 我觉得泪水是世间最不需要强忍的东西,有时候我也想忍住,让别人觉得我很坚强。但忍不住的时候我就不会忍,因为后来我...
    桃之yaoyao阅读 4,948评论 2 3
  • 想你了,但是不能去见你,或许我们本就不是在一个世界里。平行时空下的爱恋一个星期 三次见面就随着这个盛夏,带着我脖子...
    nsjs阅读 1,639评论 0 0
  • 博赞有机学习技巧 通过本章学习,我明白了确定时间,确定任务量可以提高效率。同时了解遗忘规律,及时复习可以增强记忆。
    张红英_1e92阅读 1,315评论 0 1

友情链接更多精彩内容