它不是非常从你想要什么的问题明确。如果这是您的功能中固定的值,那么做到这一点的唯一方法就是从您的应用中设置初始余额。通过'@beforeScenario'钩子来做到这一点可能是最简单的解决方案(因为你不能每次都在场景大纲中这样做)。
或者,如果您无法从套件中修改余额,唯一合适的选择是按照以下方式进行。这可能不像对实际价值的断言那样具体,但技术上这是同样的事情。黄瓜语言(如果可以称之为语言)不允许任何操作和场景概述可能是其中最具活力的部分。
语境
protected $balance;
/**
* @Give /^I know the balance$/
*/
public function updateBalance() {
// API call to get the balance…
$this->balance = API::getBalance();
}
/**
* @When /^I bill the card for (\d+) dollars$/
*/
public function billCard($amount) {
// API call to bill the card…
API::billCard($amount);
}
/**
* @Then /^the balance should reduce by (\d+) dollars$/
*/
public function assertBalance($amount) {
// API call to verify the balance was reduced correctly, don't forget to cast if necessary.
if ($this->balance - $amount === ($currentBalance = (int) API::getBalance())) {
$this->balance = $currentBalance;
} else {
throw new Exception();
}
}
功能
Scenario Outline: …
Given I know the balance
When I bill the card for <amount> dollars
Then the balance should reduce by <amount> dollars
Examples:
| amount |
| 5 |
| 10 |
是的,这是我目前在做什么。不幸的是,PM希望看到该功能的结果。她希望查看指定第一个值的结果列,并且后续值是上述结果减去金额列中的值。 – user3154922 2014-10-07 20:02:52
这是否意味着这是你需要的还是意味着其他的东西? :) – 2014-10-07 20:04:58
这不是我所需要的,这是我现在使用的。我已更新我的示例以显示她想看到的内容。 – user3154922 2014-10-07 20:08:34