Javascript 前端的BDD框架?
在服务器端,我们有Rspec/Cucumber for BDD development(ruby)vowsjs(node.js) 是否有BDD框架可用于web浏览器(不是qUnit或YUI测试,因为它们仅用于TDD)?查看jasmineJavascript 前端的BDD框架?,javascript,tdd,yui,bdd,qunit,Javascript,Tdd,Yui,Bdd,Qunit,在服务器端,我们有Rspec/Cucumber for BDD development(ruby)vowsjs(node.js) 是否有BDD框架可用于web浏览器(不是qUnit或YUI测试,因为它们仅用于TDD)?查看jasmine describe("Jasmine", function() { it("makes testing JavaScript awesome!", function() { expect(yourCode).toBeLotsBetter(); })
describe("Jasmine", function() {
it("makes testing JavaScript awesome!", function() {
expect(yourCode).toBeLotsBetter();
});
});
如果你(原文如此)对一个红宝石人来说很熟悉的话我想再看看茉莉花,也看看 另外值得注意的是——它是一个用于javascript的小黄瓜(Cumber DSL)解析器,最初它的目标是Vows.js,但它也可以生成普通的旧javascript存根(不过,现在仍然有很多错误)。下面是节点wiki上列出的一个列表 看起来很有希望。下面是语法示例: 要素来源
Feature: Simple maths
In order to do maths
As a developer
I want to increment variables
Scenario: Increment variable once
Given a variable set to 1
When I increment the variable by 1
Then the variable should contain 2
步骤定义
var variable;
Given(/^a variable set to (\d+)$/, function(number, callback) {
variable = parseInt(number);
callback();
});
When(/^I increment the variable by (\d+)$/, function(number, callback) {
variable += parseInt(number);
callback();
});
Then(/^the variable should contain (\d+)$/, function(number, callback) {
if (variable != parseInt(number))
throw(new Error('Variable should contain '+number+' but it contains '+variable+'.'));
callback();
});
你也可以看看。它不是像CucumberJS这样的独立测试框架,而是能够使用来自其他框架(如Mocha、Jasmine、CasperJS、Zombie、Qunit等)的类似黄瓜的语法。现在有了karma CucumberJS,它可以在真实浏览器和PhantomJS中进行Cucumber测试
我认为jasmine只是一个TDD框架,而不是BDD,因为它没有BDD框架所具有的两层抽象:
Scenario: Addition of numbers
Given I have multiple numbers
When I add these numbers together
Then I should get their sum as result
这就是我现在喜欢的。我使用步骤定义来设置fixture和断言的值,但是ofc。如果需要,您可以提供示例
:
Scenario: Addition of numbers
Given I have <multiple numbers>
When I add these numbers together
Then I should get <their sum> as result
Examples:
| multiple numbers | their sum |
| 1, 2, 3, 6 | 12 |
| 8, 5 | 13 |
| 5, -10, 32 | 27 |
也许调试起来更容易一些,但是您必须为这些值编写解析器,例如拆分“1,2,3,6”字符串并解析这些值以获得数字数组。我想你可以决定哪条路更适合你
高抽象级别特性描述的真正有趣之处在于,您可以编写多个不同的步骤定义。例如,您可以测试两个不同的API,它们做相同的事情,或者使用计算器示例,您可以为多个用户界面(cli、webapplication等)编写e2e测试,或者您可以编写一个简单的测试,只测试域。无论如何,功能描述或多或少是可重用的
更新2016-04-15:
我决定用with代替with。我也喜欢黄瓜和茉莉花,但我认为雅达和摩卡更灵活。你也可以看看。它不是CucumberJS这样的独立测试框架,而是在其他框架(如Mocha、CasperJS、Qunit等)中启用BDD。请回答这个问题,而不是发表评论,我会投赞成票。其他答案要么过于面向TDD(即验收测试不支持小黄瓜语法),要么无法在浏览器中运行(cucumber js)。Jasmine和Mocha都不支持纯英语验收测试。对我来说,这就是BDD(相对于TDD)的全部要点。我想与利益相关者就行为达成一致,然后(持续)对此进行测试,以便所有相关方都承担责任。@JohnSyrinek有更好的选择吗?我可以看出你们喜欢那个里的雅达,由史蒂夫抚养,但它仍然是建立在其他像茉莉花(我对这一切都很陌生)的基础上的。op确实提到了Cumber,这看起来已经是他选择Yadda做的事情了,所以我认为jasmine在这里更有意义。另外,cucumber似乎比Yadda或Kyuri更稳定(像jasmine)。@Cawas Yadda是IMO的位置。有了Yadda,您可以在步骤定义中使用TDD库(jasmine、Mocha等)。Yadda在这些TDD库的基础上添加了纯英语语言支持。Cucumber是验收测试的一种特定语言(给定时间)。Yadda使用这种开箱即用的方法,但也允许您完全定制测试解析器以满足您的需要。至于稳定性,雅达相当稳定——我从来没有遇到过问题。我在以前的一个项目上构建了类似Moonraker的东西,并建议从那里开始。我一直在研究使用Karma和Mocha在真实浏览器中运行验收测试。据我所知,Cucumber不能在浏览器中运行。使用require()和其他节点库最多只能使这一点变得困难,甚至可能是不可能的。我在这里复制并粘贴了我自己的评论,以便人们可以对其进行投票(正如约翰·西里内克所建议的那样)。看来事与愿违了!美好的我试试看。我也喜欢cucumber,无论是使用断言库还是TDD框架编写步骤定义都很好。总有一天我们会找到错误的答案。最近遇到这种情况的人,请注意,茉莉属植物自2011年以来就没有被保留过。不过,我不确定它是否仍然有效。
Scenario: Addition of numbers
Given I have multiple numbers
When I add these numbers together
Then I should get their sum as result
Scenario: Addition of numbers
Given I have <multiple numbers>
When I add these numbers together
Then I should get <their sum> as result
Examples:
| multiple numbers | their sum |
| 1, 2, 3, 6 | 12 |
| 8, 5 | 13 |
| 5, -10, 32 | 27 |
Given I have 1, 2, 3, 6
When I add these numbers together
Then I should get 12 as result