自动化测试开发:Cucumber 项目的结构优化与 Bug 修复
1. 代码优化与结构调整
1.1 初始代码与问题发现
在编写自动化测试代码时,我们从一个简单的现金取款场景开始,以下是部分代码示例:
When /^I withdraw (#{CAPTURE_CASH_AMOUNT})$/ do |amount|
teller.withdraw_from(my_account, amount)
end
这段代码定义了一个步骤,当执行“我取出一定金额”的操作时,调用 teller 对象的 withdraw_from 方法。但在运行测试时发现, CashSlot 类缺少 dispense 方法,于是我们实现了该方法:
class CashSlot
def contents
@contents or raise("I'm empty!")
end
def dispense(amount)
@contents = amount
end
end
再次运行测试,场景通过:
Feature: Cash Withdrawal
Scenario: Successful withdrawal from an account in credit
Giv
超级会员免费看
订阅专栏 解锁全文
1609

被折叠的 条评论
为什么被折叠?



