node.js 的 BDD 和 TDD?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4706020/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 13:49:30  来源:igfitidea点击:

BDD and TDD for node.js?

node.jsrspectddcucumberbdd

提问by donald

What is used for BDD and TDD with node.js?

node.js 的 BDD 和 TDD 使用什么?

I'm used to use Cucumber + RSpec. What's a good combo for node.js?

我习惯使用 Cucumber + RSpec。什么是 node.js 的好组合?

thanks

谢谢

采纳答案by Alfred

Update

更新

Mochagets my vote now!

摩卡现在得到我的投票!



You could have a look at the testing modules sectionfrom the node.js modules page. For example Vowsis a pretty popular BDD framework.

您可以从 node.js 模块页面查看测试模块部分。例如,Vows是一个非常流行的 BDD 框架。

Vows is a behavior driven development framework for Node.js.

Vows 是 Node.js 的行为驱动开发框架。

回答by Quang Van

Check out mocha- (github)

查看摩卡咖啡- (github)

Also mocha-cakes, my attempt for Cucumber syntax on mocha.

还有mocha-cakes,我尝试在 mocha 上使用 Cucumber 语法。

回答by Craig Monson

If you are used to rspec, Jasmineis pretty nice. I've not used it on Node.js, but I have used it for testing a backbone app. It's syntax is very similar to rspec. Taken from the site above:

如果你习惯了 rspec,Jasmine是相当不错的。我没有在 Node.js 上使用它,但我已经用它来测试一个主干应用程序。它的语法与 rspec 非常相似。取自上面的网站:

describe("Jasmine", function() {
  it("makes testing JavaScript awesome!", function() {
    expect(yourCode).toBeLotsBetter();
  });
});

It's listed in the link provided by Alfred above, but since folks listed Vows as an example, I figured I'd give Jasmine a bump, especially since it's syntactically similar to rspec ;)

它列在上面由 Alfred 提供的链接中,但由于人们以 Vows 为例,我想我会给 Jasmine 一个冲击,特别是因为它在语法上类似于 rspec ;)

回答by Nikolay

There is the 'Vows' project for BDD on Node http://vowsjs.org, looks pretty nice. It's a bit different from RSpec/Cucumber, but it's pretty fun

Node http://vowsjs.org上有 BDD 的“誓言”项目,看起来很不错。和 RSpec/Cucumber 有点不同,但是很好玩

回答by Benja

Maybe a little later, but what you're looking for is Kyuri: https://github.com/nodejitsu/kyuri

也许稍后,但你要找的是 Kyuri:https: //github.com/nodejitsu/kyuri

"kyuri is a node.js Cucumber implementation with a few extra asynchronous keywords. it supports 160+ languages and exports to VowsJS stubs"

“kyuri 是一个带有一些额外异步关键字的 node.js Cucumber 实现。它支持 160 多种语言并导出到 VowsJS 存根”

Also, nodejitsu seems to have built a web app for managing a project Kyuri feature specs in a collaborative way, it's named "prenup", I would give it a look.

此外,nodejitsu 似乎已经构建了一个 Web 应用程序,用于以协作方式管理项目 Kyuri 功能规范,它名为“prenup”,我想看看。

回答by cressie176

You could also try yadda. It plugs into other test libraries including mocha, jasmine, casper & webdriver, but also lets you write proper feature files instead of merely annotating you tests in situ. A typical test might look like...

你也可以试试yadda。它可以插入其他测试库,包括 mocha、jasmine、casper 和 webdriver,还可以让您编写适当的功能文件,而不仅仅是在原位注释测试。一个典型的测试可能看起来像......

var Yadda = require('yadda');
Yadda.plugins.mocha();

feature('./features/bottles.feature', function(feature) {

   var library = require('./bottles-library');
   var yadda = new Yadda.Yadda(library);

   scenarios(feature.scenarios, function(scenario, done) {
      yadda.yadda(scenario.steps, done);
   });
});

And the feature file...

和功能文件...

Feature: Mocha Asynchronous Example

Scenario: A bottle falls from the wall

Given 100 green bottles are standing on the wall
when 1 green bottle accidentally falls
then there are 99 green bottles standing on the wall

And output...

和输出...

Mocha Asynchronous Example
? A bottle falls from the wall 

1 passing (12ms)

回答by Tauren

Check out Buster.JS. Created by Christian Johansen, who literally wrote the book on javascript testing.

查看Buster.JS。由 Christian Johansen 创建,他写了一本关于 javascript 测试的书

Buster supports both TDD and BDD. It does browser testing with browser automation (think JsTestDriver), QUnit style static HTML page testing, testing in headless browsers (PhantomJS, jsdom), and more.

Buster 支持 TDD 和BDD。它使用浏览器自动化进行浏览器测试(想想 JsTestDriver)、QUnit 风格的静态 HTML 页面测试、无头浏览器测试(PhantomJS、jsdom)等等。

回答by Lars-Erik Roald

Package a(bdd and mocking) https://npmjs.org/package/a

打包a(bdd和mocking) https://npmjs.org/package/a

Very compact syntax, context separated from acts, chainable acts. Easy Cmd line runner that searches recursively.

非常紧凑的语法,上下文与行为分离,可链接的行为。递归搜索的简单 Cmd 行运行器。

回答by Thomas Bratt

Unit tests: Mochais great for unit tests.

单元测试Mocha非常适合单元测试。

BDD testsIf you want a BDD test framework for Node.js then I'd recommend the Cucumberpackage.

BDD 测试如果你想要一个 Node.js 的 BDD 测试框架,那么我推荐Cucumber包。

回答by user3251882

I was going through the same concern last month .

上个月我也经历了同样的担忧。

For BDD :

对于 BDD :

Though Mocha itself provides BDD style by their describe and it statements.

尽管 Mocha 本身通过其 describe 和 it 语句提供了 BDD 风格。

For styles like cucumber , you can try :

对于像黄瓜这样的风格,你可以尝试:

  • mocha-cakes
  • mocha-gherkin
  • cucumber.js
  • kyuri
  • mocha-cucumber
  • 摩卡蛋糕
  • 摩卡小黄瓜
  • 黄瓜.js
  • 久里
  • 摩卡黄瓜

They all have their own styles. I am sorry I can not provide working snippets now , let me know @Donald which one you select. Would like to know your insight.

他们都有自己的风格。很抱歉,我现在无法提供工作片段,请告诉我 @Donald 您选择了哪一个。想知道你的见解。