Karma的第一次使用
2016-02-02 21:04
846 查看
Karma 中文意思为因果报应
这是一个写AngularJs的工程师们写的一个测试工具
这里是Karma的官网Karma
首先我的电脑是事先安装了node.js和npm的
第一步先安装Karma,在命令行中输入
安装成功
接下来安装用Jasmine(茉莉花Jasmine)单元测试框架所必需的插件
但是现在还不能够使用Karma start等指令
需要在命令行中输入
接下来进入事先建立好的文件夹
我这里是winterexercise文件夹
该文件夹下有两个子文件夹分别为tobetest和test
两个文件夹中分别是待测js文件和测试代码
在命令行中进入到winterexercise目录下
根据提示选择一些选项,比如
这里我选择的是Jasmine框架
这是对浏览器进行选择
提示输入待测文件和测试文件的目录
这里输入
Karma会自动进行匹配
选择结束之后,会在winterexercise文件夹中生成一个js文件karma.config.js
在这个配置文件中我们可以自己动手对刚才的配置选项进行修改
在命令行中输入
将自动弹出Chrome浏览器
内容如下图所示
我们再去命令行中查看
到这里,我的第一个小程序就算是测试成功了!
这是一个写AngularJs的工程师们写的一个测试工具
这里是Karma的官网Karma
首先我的电脑是事先安装了node.js和npm的
第一步先安装Karma,在命令行中输入
npm install -g Karma
安装成功
接下来安装用Jasmine(茉莉花Jasmine)单元测试框架所必需的插件
npm install -g karma-jasmine npm install -g karma-chrome-launcher
但是现在还不能够使用Karma start等指令
需要在命令行中输入
install -g karma-cli
接下来进入事先建立好的文件夹
我这里是winterexercise文件夹
该文件夹下有两个子文件夹分别为tobetest和test
两个文件夹中分别是待测js文件和测试代码
//tobetest/add.js function add(a, b){ c = a + b; return c; }
//test/testAdd.js describe("a suit to test", function () { it("should it pass", function () { expect(add(1, 3)).toEqual(4); //expect(add(4, 7)).toEqual(18); }); });
在命令行中进入到winterexercise目录下
➜ winterexcise karma init karma.config.js
根据提示选择一些选项,比如
Which testing framework do you want to use ? Press tab to list possible options. Enter to move to the next question. > jasmine
这里我选择的是Jasmine框架
Do you want to capture any browsers 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.
提示输入待测文件和测试文件的目录
这里输入
> tobetest/*.js > test/*.js
Karma会自动进行匹配
选择结束之后,会在winterexercise文件夹中生成一个js文件karma.config.js
在这个配置文件中我们可以自己动手对刚才的配置选项进行修改
在命令行中输入
karma start karma.config.js
将自动弹出Chrome浏览器
内容如下图所示
我们再去命令行中查看
到这里,我的第一个小程序就算是测试成功了!
相关文章推荐
- JQuery1——基础($对象,选择器,对象转换)
- Android学习笔记(二九):嵌入浏览器
- Android java 与 javascript互访(相互调用)的方法例子
- 使用 HTTP 上传 G 级的文件之 Node.js 版本
- JavaScript演示排序算法
- mongo实现消息队列
- javascript实现10进制转为N进制数
- Node.js压缩web项目中的js,css和图片
- 2019年开发人员应该学习的8个JavaScript框架
- HTML中的script标签研究
- 对一个分号引发的错误研究
- async.js 学习记录
- 异步流程控制:7 行代码学会 co 模块
- ES6 走马观花(ECMAScript2015 新特性)
- JavaScript拆分字符串时产生空字符的原因
- Canvas 在高清屏下绘制图片变模糊的解决方法