【发布时间】:2015-01-06 16:39:22
【问题描述】:
我正在尝试使用 describe 和 it 将我的用户故事转换/翻译成 mocha 规范。我觉得有点混乱。
举个例子:
Story: Account Holder withdraws cash
As an Account Holder
I want to withdraw cash from an ATM
So that I can get money when the bank is closed
Scenario 1: Account has sufficient funds
Given the account balance is \$100
And the card is valid
And the machine contains enough money
When the Account Holder requests \$20
Then the ATM should dispense \$20
And the account balance should be \$80
And the card should be returned
Scenario 2: Account has insufficient funds
Given the account balance is \$10
And the card is valid
And the machine contains enough money
When the Account Holder requests \$20
Then the ATM should not dispense any money
And the ATM should say there are insufficient funds
And the account balance should be \$20
And the card should be returned
因此,使用 mocha 的“describe”和“it”,最好的翻译方式是什么。我见过的大多数示例都以测试函数和方法的方式使用 BDD——这对我来说真的更像是 TDD。
编辑
我也想使用模拟;如果我准确地翻译用户故事,那么我可以模拟吗?
【问题讨论】:
-
您可以使用cucumber.js 直接针对这些文件运行测试。
-
describe("withdraw cash"),与it("has sufficient funds")和it ("doesn't have sufficient funds")。你可以写一个端到端的测试来运行整个链的任何函数。我不确定问题是什么;你有一个起点和终点。只需使用给定的起点测试终点的结果。如果您想知道它在哪里中断(如果它中断),只需为 TDD 编写另一套测试。我误解了这个问题吗?
标签: javascript node.js bdd mocha.js user-stories