我有一个类似这样的功能测试。
Given I am a Bank Customer
And My Starting Balances Are
| Account Type | Balance |
| Checking | 98.00 |
When on Day 1 I make DOLLAR AMT withdrawal from my existing balances
| Account Type | Balance |
| Checking | 98.00 |
我想做的是取整数值并从余额中减去它,然后将该值重新分配给数据表并将其传递。
我知道我可以从表中获取值,将其分配给变量,然后对其进行操作。我需要将更新后的值放回去。
编辑-这是我到目前为止的内容。它会计算新的余额,但我需要将该值重新插入DT。
public void myUpdatedCheckingBalance(int cashAmt, DataTable balances) throws Throwable {
List<List<String>> balanceData = balances.raw();
String origBal;
int updatedBal = 0;
for (int i = 1; i<balanceData.size(); i++){
JOptionPane.showMessageDialog(null, balanceData.get(i).get(i));
origBal = balanceData.get(i).get(i);
int balValue = Integer.parseInt(origBal);
JOptionPane.showMessageDialog(null, balValue);
updatedBal = balValue - hoursAmt;
JOptionPane.showMessageDialog(null, updatedBal);
balanceData.set(arg0, arg1)
}
JOptionPane.showMessageDialog(null, updatedBal);
答案 0 :(得分:1)
当您编写表达意图的简单方案时,黄瓜效果最佳,这就是您正在做的事情以及其重要性的原因。如何做某事涉及的任何事情都比其他地方更好。
解决问题的一种方法就是编写表达意图的更简单的方案。例如
Scenario: Withdraw all the money in my account
Given I have an account with some money in it
When I withdraw all my money
Then my account should have no money in it
Scenario: Withdraw more money than my account holds
Given I have an account with some money in it
When I withdraw more money than my account has
Then ...
...
您可能需要几种方案来探索帐户,透支额度和余额。您无需在此处执行的操作都会放入值中。 Cukes是用于尝试定义帐户行为的业务规则,而不是技术规则。因此,您谈论的是overdraft limit
和balance
,但不要使用数字,除非它们专门增加了场景的清晰度(提示:它们从不这样做,您总是可以编写没有示例的更好的场景,例如所有示例都需要说明其示例。)