-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodejs测试(mocha)
35 lines (34 loc) · 1.42 KB
/
nodejs测试(mocha)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
1,测试逻辑程序:单元测试分为测试驱动开发TDD风格(传统测试),行为驱动开发BDD风格两种。
2,验收测试:通过测试脚本控制浏览器测试程序界面和功能。
(测试脚本)用test.js结尾。
3,assert断言模块。分为3类,肯定性断言,否定性断言,异常类断言。
var asssert = require("assert");
var Todo = require("./todo");
var todo = new Todo();
function(){
console.log("hahaha");
todo.add('delete me');
todo.deleteALL();
assert.equal(todo.getCount()(运行实际结果),0(预期结果),"正确!");
assert.notequal(todo.getCount(),1,"正确");
}
4, 测试命令
git init:初始化git版本库。
npm init:初始化项目。
npm install mocha -D:添加摩卡,放到node-module里面。
npm install chai -D:添加断言库。
git ci -m "init commit"添加版本库。
5,摩卡断言库should(),expect,assert。
expect断言库优点:
1. 更接近自然语言。
2. discribe测试套件("测试套件名称",function(){
it测试用例('测试用例名称',function()}{
expect(测试对象).to.be.equal(0);
}),
})
3. 常见用法:
3.1. 相等或者不相等:expect(4+5).to.be,equal(9);
3.2. 布尔值为true:expext("everything").to.be.ok;
3.3. typeof:expect('test').to.be.a('string');
expect(foo).to.be.an.instanceof(Foo);
3.4. include