在介绍Jasmine ,它说:
Jasmine is a behavior-driven development framework for testing JavaScript code.
我阅读了 BDD 的几篇文章,似乎我们应该使用“Given/When/Then”来定义“Scenario”,这就是“cucumber”所做的。但是在 Jasmine 中,我看不到任何这样的方法。
即使 Jasmine 没有这样的概念,我们还能称其为“BDD”测试框架吗?
最佳答案
Jasmine 不会阻止您使用 given-when-then,下面的示例显示了在使用 Jasmine 时可以使用 given-when-then 的两种方式。
describe("Given a string containing 'foo'", function(){
var someString;
beforeEach(function() {
someString = "foo";
});
describe("When I append 'bar'", function(){
beforeEach(function() {
someString += "bar";
});
it("Then the string is 'foobar'", function(){
expect(someString).toBe("foobar");
});
});
it("When I append 'baz' Then the string is 'foobaz'", function(){
someString += "baz";
expect(someString).toBe("foobaz");
});
});
找到适合您的风格。您应该确保测试描述有效地描述了您正在测试的内容。您可以使用 given-when-then 样式的句子作为一种工具,以确保您的测试描述准确说明所测试的内容。
关于javascript - 为什么 Jasmine 被称为 "BDD"测试框架,即使不支持 "Given/When/Then"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33984182/