摩卡:将用户故事翻译成描述/它的规范(BDD框架,即摩卡)
Mocha: Translating a user story to a spec of describe / it (bdd framework i.e. 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
因此,使用摩卡的"描述"和"它",翻译它的最佳方式是什么。我看到的大多数示例都以测试函数和方法的方式使用 BDD - 这对我来说更像是 TDD。
编辑
我也想使用模拟;如果我准确地翻译用户故事,那么我能模拟吗?
我对摩卡不是很熟悉,所以我为你做了一个类似的。希望你明白这个想法。
场景 1:
it should authenticate card currectly if a valid card and details are provided:
System.readCard(new Card({config}))....
expect(System.Card.isValid).toBe(true)
it should get the correct financial details from the user
// You know it's your card and you have $100
var originalBalance = System.User.Balance;
expect(originalBalance).to.be(100);
it should have enough for the user
System.User.RequestBalance = 20;
expect(System.Vault.Balance).to.be.at.least(System.User.RequestBalance);
it should dispense the requested amount:
System.Dispence(System.User.RequestBalance);
expect(System.Vault.Balance).to.be(System.Vault.Balance - System.User.RequestBalance);
it should deduct the amount from user's account
expect(System.User.Balance).to.be(originalBalance - System.User.RequestBalance);
it should return the card
Syste.ejectCard();
expect(System.CardHolder.isEmpty).to.be(true);
....等等。这只是一个快速给你一个想法。
请注意,一般的想法是你做了某事,你对结果做出断言,并检查那件事是否发生了,如果它发生了,它证明了你想要的是这种情况确实发生了。
我参加聚会有点晚了,但以防其他人有类似的需求。我有一个摩卡库,它提供了一个非常丰富的小黄瓜,也就是功能/场景/给定/何时/然后等语法。您可以在此处找到该项目:
https://github.com/dotnetprofessional/LiveDoc/tree/master/packages/livedoc-mocha
示例如下所示:
feature(`Account Holder withdraws cash
Account Holders should be able to withdraw cash at any of the
companies ATMs.
Rules:
* Account Holders should have a valid keycard
* Have sufficient available funds
* The ATM has the necessary funds
`, () => {
scenario("Account has sufficient funds", () => {
let atm = new ATM();
let cashReceived: number;
given(`the account holders account has the following:
| account | 12345 |
| balance | 100 |
| status | valid |
`, () => {
const accountHolder = stepContext.tableAsEntity;
atm.setStatus(accountHolder.account, accountHolder.status);
atm.deposit(accountHolder.account, accountHolder.balance)
});
and("the machine contains '1000' dollars", () => {
atm.addCash(stepContext.values[0]);
});
when("the Account Holder requests '20' dollars", () => {
cashReceived = atm.withDraw(scenarioContext.given.tableAsEntity.account, stepContext.values[0]);
});
then("the ATM should dispense '20' dollars", () => {
cashReceived.should.be.equal(stepContext.values[0]);
});
and("the account balance should be '80' dollars", () => {
atm.getBalance(scenarioContext.given.tableAsEntity.account).should.be.equal(stepContext.values[0]);
});
});
});
相关文章:
- 摩卡由于绝对路径而不断轰炸
- 如何使用浏览器中用酶创建的组件反应例如摩卡
- 找不到模块'它'当用摩卡/柴测试时
- 摩卡+柴+jsdom Can't加载自定义模块目录
- 如何将 XML 文件包含在摩卡测试用例中
- 摩卡与敏捷(异步)冲突
- 用于摩卡测试的 CLI 调试器
- 如何在摩卡测试中使用“定义”
- 摩卡“每个钩子之前”红色消息.我怎么知道具体出了什么问题
- 错误:使用摩卡测试时找不到模块
- 大口喝摩卡如何传递编译器标志
- 我可以从摩卡测试MarkLogic SJS吗
- 用摩卡测试失败的承诺'内置的promise支持
- 如何用摩卡/柴制作模拟窗口/文档
- 使用带量角器的摩卡无法通过超时测试
- 未定义的Es6级在单元测试中与大口摩卡
- 摩卡和西农方法间谍
- 从命令行一次运行大量摩卡测试的好方法是什么
- 摩卡:将用户故事翻译成描述/它的规范(BDD框架,即摩卡)
- 摩卡 bdd 风格测试命名