调试Cucumber测试程序

xiaoxiao2026-08-17  2

Cucumber已经成为广泛接受的集成测试工具,Rails的开发的热门。那么,下面将专门讨论对于写cucumber测试的调试(Debug) [b][size=medium]ruby-debug breakpoint[/size][/b] 首先,添加调试支持环境,到对应的features/support/env.rb. require 'ruby-debug' 添加断点 Then /^the process should exit cleanly$/ do breakpoint assert @exited_cleanly, "Process did not exit cleanly: #{@stdout}"end 这里特别说明,如果你把断点breakpoint加到了一个block的最后,会进入调用部分。例如,下面这样会好一些。 <notextile> Then /^the process should exit cleanly$/ do assert @exited_cleanly, "Process did not exit cleanly: #{@stdout}" breakpoint; 0end </notextile> [b][size=medium]开始debug[/size][/b] 使用“Then I debug”放到 features/step_definitions/debug_steps.rb:将会很方便 Then /^I debug$/ do breakpoint 0end 这样写的好处在于可以方便的添加到你要测试的代码部分。如果,你把断点放到有问题的部分可能会比较不容易定位问题。 [b][size=large]Webrat[/size][/b] Webrat是Rails默认的cucumber测试工具,将提供诸如点击链接,输入和提交表单的操作。如果,你的模拟点击的元素不存在,将会产生很多的html反馈。 [b][size=large]save_and_open_page[/size][/b] Webrat提供save_and_open_page来捕获当前的HTML页面并保存。如下使用: When /^I follow "(.*)"$/ do |link| save_and_open_page click_link(link)end 可是,这就有一个问题,如果,在测试的时候有太多的页面被保存,那么读取就很不方便 When /^I follow "(.*)"$/ do |link| begin click_link(link) rescue save_and_open_page raise end end [b][size=medium]结论[/size][/b] Cucumber 可以结合 ruby-debug save_and_open_page进行调试 相关资源:敏捷开发V1.0.pptx
转载请注明原文地址: https://www.6miu.com/read-5051363.html

最新回复(0)