Exploration Through ExampleExample-driven development, Agile testing, context-driven testing, Agile programming, Ruby, and other things of interest to Brian Marick
|
Thu, 13 Oct 2005At PNSQC, Michael Kelly gave a talk. Among other things, it covered converting functional test scripts into performance test scripts. He gave examples using several tools, one of them Watir. As he described how little of the test script had to change to make it a performance test script, I realized that there was a way to make it require no changes. I didn't quite finish a demo during his talk, but I did shortly after. Here's an example: Load (a fake version of) Watir, get an object representing IE, and ask it to go to a URL. irb(main):001:0> require 'watir' => true irb(main):002:0> ie = IE.new => #<IE:0x329144> irb(main):003:0> ie.goto('url') => "here's a bunch of HTML" (I faked out Watir because I didn't have net access and, anyway,
this machine is a Mac.) What you can't see in the above is
that Now I want to run the same "test", timing all gotos. irb(main):004:0> require 'perf' => true irb(main):005:0> IE.time(:goto) => nil irb(main):006:0> ie.goto('url') 1.000129 => "here's a bunch of HTML" It took just over a second. Here's the code. Mike will be seeing about getting something like it into the Watir distribution. class IE def self.time(method) method = method.to_s original_method = '__orig__' + method new_def = "alias_method :#{original_method}, :#{method} def #{method}(*args, &block) start = Time.now retval = #{original_method}(*args, &block) puts Time.now - start retval end" class_eval(new_def) end end Take that, WinRunner! |
|