Nar*_*esh 5 cucumber cucumberjs
我只是在学习Cucumber,并注意到如果两个完全独立的功能有两个意外措辞相同的步骤,Cucumber建议他们只有一个步骤定义.这是否意味着步骤定义是全局的并且它们是要共享的?
假设一个业务分析师团队正在为一家拥有银行部门和经纪部门的金融公司编写规范.进一步假设两个不同的人正在为各自的部门编写特征来计算交易费用.
银行家伙写道:
Feature: Transaction Fees
Scenario: Cutomer withdraws cash from an out-of-netwrok ATM
Given that a customer has withdrawn cash from an out-of-netwrok ATM
When I calculate the transaction fees
Then I must include an out-of-netwrok ATM charge
Run Code Online (Sandbox Code Playgroud)
经纪人写道
Feature: Transaction Fees
Scenario: Cutomer places a limit order
Given that a customer has placed a limit order
When I calculate the transaction fees
Then I must include our standard limit-order charge
Run Code Online (Sandbox Code Playgroud)
请注意,两个方案的When子句相同.更糟糕的是,两个人都把这个场景放在一个名为transaction-fees.feature的文件中(当然在不同的目录中).
黄瓜为步骤定义提出以下建议:
You can implement step definitions for undefined steps with these snippets:
this.Given(/^that a customer has withdrawn cash from an out\-of\-netwrok ATM$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.When(/^I calculate the transaction fees$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.Then(/^I must include an out\-of\-netwrok ATM charge$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.Given(/^that a customer has placed a limit order$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
this.Then(/^I must include our standard limit\-order charge$/, function (callback) {
// Write code here that turns the phrase above into concrete actions
callback.pending();
});
Run Code Online (Sandbox Code Playgroud)
请注意,when子句仅建议一次.
提前感谢您的时间和澄清.
步骤定义附加到 World 对象,即上面代码中的“this”。
应该只有一个步骤定义。它们是为了共享。IIRC,Cucumber Boo,第 149 页 ( https://pragprog.com/book/hwcuc/the-cucumber-book ) 详细介绍了此设计决策。虽然它是 ruby,但我认为这在所有 Cucumber 实现中都是相同的。
Cucumber 不关联特征文件和step_definition 文件。文件树/约定只是为了方便。
| 归档时间: |
|
| 查看次数: |
1690 次 |
| 最近记录: |