1 或 2 描述了摩卡测试中的功能?
1 or 2 describes for a function in mocha tests?
我正在为 Node 应用程序编写有关 Mocha 的教程。
http://code.tutsplus.com/tutorials/testing-in-nodejs--net-35018
它有这个代码
describe("Tags", function(){
describe("#parse()", function(){
it("should parse long formed tags", function(){
var args = ["--depth=4", "--hello=world"];
var results = tags.parse(args);
expect(results).to.have.a.property("depth", 4);
expect(results).to.have.a.property("hello", "world");
});
});
});
为什么我不能只有一个描述行?
像这样
describe("Tags #parse()", function(){
it("should parse long formed tags", function(){
var args = ["--depth=4", "--hello=world"];
var results = tags.parse(args);
expect(results).to.have.a.property("depth", 4);
expect(results).to.have.a.property("hello", "world");
});
});
每个 describe
创建一个不同的测试,每个 it
将在测试下测试不同的 "behavior"。
例如,在测试 class 或模块时,创建顶级 describe("MyModule", ...)
和多个嵌套 describe
调用是一种很好的方式,每个 method/function等等
这一切都归结为测试的风格和粒度。理论上你可以用一个 describe 测试你的整个 API ,如果你愿意的话也可以用一个 it 。使其细化意味着当测试失败、重构或更改 API 等时,您可以进行更细粒度的控制。
您完全可以按照自己喜欢的方式设计测试。
我正在为 Node 应用程序编写有关 Mocha 的教程。 http://code.tutsplus.com/tutorials/testing-in-nodejs--net-35018
它有这个代码
describe("Tags", function(){
describe("#parse()", function(){
it("should parse long formed tags", function(){
var args = ["--depth=4", "--hello=world"];
var results = tags.parse(args);
expect(results).to.have.a.property("depth", 4);
expect(results).to.have.a.property("hello", "world");
});
});
});
为什么我不能只有一个描述行? 像这样
describe("Tags #parse()", function(){
it("should parse long formed tags", function(){
var args = ["--depth=4", "--hello=world"];
var results = tags.parse(args);
expect(results).to.have.a.property("depth", 4);
expect(results).to.have.a.property("hello", "world");
});
});
每个 describe
创建一个不同的测试,每个 it
将在测试下测试不同的 "behavior"。
例如,在测试 class 或模块时,创建顶级 describe("MyModule", ...)
和多个嵌套 describe
调用是一种很好的方式,每个 method/function等等
这一切都归结为测试的风格和粒度。理论上你可以用一个 describe 测试你的整个 API ,如果你愿意的话也可以用一个 it 。使其细化意味着当测试失败、重构或更改 API 等时,您可以进行更细粒度的控制。
您完全可以按照自己喜欢的方式设计测试。