测试自动化与Cucumber的综合应用
1. 计算器应用与Aruba测试
首先来看一个简单的计算器应用示例:
numbers_to_add.each do |number|
total += number
end
print(total)
当没有命令行参数时,计算器会提示用户输入计算式并等待输入。以下是使用Aruba进行测试的相关场景:
| 场景 | 描述 |
| — | — |
| 场景1:添加两个数字 | 给定输入 “2+2”,运行计算器,输出应为 “4” |
| 场景2:交互式添加两个数字 | 无输入运行计算器,输入计算式 “2+2”,输出应为 “4” |
测试结果显示两个场景均通过,这表明对计算器的修改未破坏现有功能。为了让代码更简洁,我们可以直接使用Aruba的API,而不是委托其步骤定义。以下是将Aruba步骤定义转换为底层方法调用后的代码:
Given /^the input "([^"]*)"$/ do |input|
write_file 'input.txt', input
end
When /^the calculator is run$/ do
run 'calculator input.txt'
end
When /^the calculator is run with no input$/ do
run_interactive 'calculator'
end
When /^I enter the calculation "(
超级会员免费看
订阅专栏 解锁全文
169

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



