前端的 BDD 框架?
在服务器端,我们有用于 BDD 开发的 Rspec/Cucumber (ruby) vowsjs (node.js)
是否有可在 Web 浏览器上使用的 BDD 框架(不是 qUnit 或 YUI 测试,因为它们仅适用于 TDD)?
On the server side we have Rspec/Cucumber for BDD development (ruby) vowsjs (node.js)
Is there a BDD frameworks to use on web browsers (not qUnit or YUI test since these are only for TDD)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
查看茉莉花
http://pivotal.github.com/jasmine/
https://github.com/pivotal/jasmine
Should_be (原文如此) 对于 ruby 人来说非常熟悉
Check out jasmine
http://pivotal.github.com/jasmine/
https://github.com/pivotal/jasmine
Should_be ( sic ) very familiar to a ruby person
您还可以查看 Yadda。它不是像 CucumberJS 这样的独立测试框架,而是可以使用 Mocha、Jasmine、CasperJS、Zombie、Qunit 等其他框架的类似 Gherkin 的语法。
You could also look at Yadda. Rather than being a standalone test framework like CucumberJS, it enables to use a Gherkin like syntax from other frameworks like Mocha, Jasmine, CasperJS, Zombie, Qunit etc.
我第二个茉莉花,也看看 Jasmine-species
另外值得注意的是 Kyuri -- 这是一个用于 javascript 的 Gherkin(Cucumber DSL)解析器,最初它针对的是 Vows.js,但它也可以生成普通的旧 JavaScript 存根(但是,它现在仍然有很多错误)。
I'd second Jasmine, also take a look at Jasmine-species
Also of note is Kyuri -- It's a Gherkin (the Cucumber DSL) parser for javascript, originally it targeted Vows.js, but it also can generate plain old javascript stubs (however, it's still pretty buggy right now).
以下是 Node wiki 上列出的测试框架列表。
cucumber-js 看起来很有前途。以下是语法示例:
特征源
步骤定义
Here's a list of testing frameworks listed on the node wiki.
cucumber-js looks promising. Here's a sample of the syntax:
Feature source
Step definitions
我认为 jasmine 只是一个 TDD 框架,而不是 BDD,因为它没有 BDD 框架所具有的两层抽象:
但是没关系,这是一个很好的起点。我也不喜欢重新发明轮子(使用基于 txt 的语言)。我找到了一个基于 jasmine 构建的 BDD 框架,对我来说这是完美的解决方案: https:/ /github.com/DealerDotCom/karma-jasmine-cucumber
例如:
specs.js(我们做什么)
steps.js(我们如何做)
2016-02-16 更新:
经过几个月的 BDD 练习,我最终得到了基于 txt 的功能描述和 ofc。与小黄瓜。我认为最好在功能描述中写入一些非常高的抽象级别的内容,而不是我之前在 karma-jasmine-cucumber 示例中写入的内容。按照我以前的例子,我现在宁愿写这样的东西:
这就是我目前喜欢的方式。我使用步骤定义来设置装置和断言的值,但是ofc。如果需要,您可以使用 gherkin 提供
示例
:Cucumber 将这 3 行转换为 3 个场景,例如:
也许调试起来更容易,但是你必须为这些编写解析器值,例如拆分“1,2,3,6”字符串并解析这些值以获得数字数组。我认为您可以决定哪种方式更适合您。
高抽象级别的功能描述真正有趣的是,您可以编写多个不同的步骤定义。例如,您可以测试 2 个不同的 api,它们执行相同的操作,或者继续使用计算器示例,您可以为多个用户界面(cli、webapplication 等)编写 e2e 测试,或者您可以编写一个简单的测试,其中仅测试域。无论如何,功能描述或多或少是可重用的。
2016-04-15更新:
我决定将 Yadda 与 mocha 而不是 黄瓜与茉莉花。我也喜欢黄瓜和茉莉花,但我认为雅达和摩卡更灵活。
I think jasmine is just a TDD framework, not a BDD, because it does not have the two layers of abstraction BDD frameworks have:
But that's okay, it is a good starting point. I don't like reinventing the wheel (using a txt based language) either. I have found a BDD framework, which builds on jasmine, to me this was the perfect solution: https://github.com/DealerDotCom/karma-jasmine-cucumber
For example:
specs.js (what we do)
steps.js (how we do it)
Update 2016-02-16:
After a few months of practice with BDD I ended up with txt based feature descriptions and ofc. with gherkin. I think it is better to write something really high abstraction level into the feature descriptions instead of what I previously wrote into my karma-jasmine-cucumber example. By my old example I would rather write something like this nowadays:
This is how I like it currently. I use to let the step definitions to set the values of the fixtures and the assertions, but ofc. you can give
Examples
with gherkin if you want:Cucumber translates these 3 rows to 3 scenarios, e.g:
Maybe it is somewhat easier to debug, but you have to write parser for these values, for example split the "1, 2, 3, 6" string and parseInt the values to get the numbers array. I think you can decide which way is better for you.
What is really interesting with high abstraction level feature descriptions, that you can write multiple different step definitions. So for example you can test 2 different apis, which do the same thing, or to stick with the calculator example, you can write e2e tests for multiple user interfaces (cli, webapplication, etc.) or you can write a simple test, which tests the domain only. Anyways the feature descriptions are more or less reusable.
Update 2016-04-15:
I decided to use Yadda with mocha instead of Cucumber with jasmine. I liked Cucumber and jasmine too, but I think Yadda and mocha are more flexible.
现在有 karma-cucumberjs 可以在真实浏览器和 PhantomJS 中进行 Cucumber 测试。
https://github.com/s9tpepper/karma-cucumberjs
There's now karma-cucumberjs which can do Cucumber testing in real browsers as well as PhantomJS.
https://github.com/s9tpepper/karma-cucumberjs
我可以推荐使用 WebdriverIO + CucumberJS 的 BDD 方法,如果您使用 Jira,您可以通过 Jira Xray 管理您的测试并尝试使用 Sauce Labs 进行云测试。
I can recommend BDD approach with WebdriverIO + CucumberJS, also if you are using Jira you can manage your tests with requirements via Jira Xray and also try cloud testing with Sauce Labs.