I tried posting this to the mailing list last night to no avail, so if this does show up as a double post I apologize in advance.

I've been using Watir for the past couple of weeks with great success. My company has been able to stay a bit more agile when it comes to releases because of the unit tests for the code and because of the Watir tests for the interfaces we've been building. It's made for some less stressful releases - so I'm very thankful to the Watir community for this.

I've been chewing on a problem for the past couple of weeks and getting no success. I don't think it's a problem with Watir as much as it's my inexperience with Ruby.

My problem is this: What if I want to run a unit test multiple times but with different data each time through the test?

For example, let's say I have the following unit test - I'm using MapQuest here as an example. My real world example does deal with addresses - and MapQuest is a good example, I think.

Here's some sample code:

*** begin code ***

require 'watir'
require 'test/unit'
include Watir

class MultipleAddressTest < Test::Unit::TestCase

  def setup
    $testSite = "http://www.mapquest.com"
    $street = "123 Foo"
    $zip = "90210"
    $ie = IE.new
    $ie.set_fast_speed
    $ie.goto($testSite)
    $ie.wait
  end

  def test_directions
    $ie.text_field(:name, "address").set($street)
    $ie.text_field(:name, "zipcode").set($zip)
    $ie.button(:value, "Get Directions").click
    sleep 7
    $ie.close
  end

end

*** end code ***

My problem is this - how can I run this same unit test multiple times for different addresses. My object orientation isn't so good, and I'm not really familiar with Unit Tests outside of what's in Watir's limited documentation. Anyway, I digress.

Let's say I have a hash that I can iterate through:

*** begin pseduo code ***

$plans = {
  "1181" => {
    "street" => "36 Dearborn Street",
    "zip" => "01979"
  },
  "1183" => {
    "street" => "940 10th Street",
    "zip" => "80302"
  },
  "1184" => {
    "street" => "14030 Biscayne Blvd",
    "zip" => "33181"
  },        
  "1185" => {
    "street" => "807 Reilly Ct",
    "zip" => "95747"
  },
  "1187" => {
    "street" => "21388 West Lane",
    "zip" => "19958"
  },
  "1188" => {
    "street" => "7877 Forest Blvd",
    "zip" => "55125"
  },
  "1189" => {
    "street" => "10 River Walk Plaza",
    "zip" => "55107"
  }
}

$plans.each_value do |plan|
  street = plan['street']
  zip = plan['zip']
  puts street, zip
end

*** end pseudo code ***

How do I link up the ability to iterate through this hash for each pair of addresses and zip codes with the Unit Test that takes address and zip as inputs? I'd rather not write multiple tests that do the same thing - seems repetitive work for a task that should be easy to accomplish with an iterator.

I hope I'm being clear - can anyone help me? I'm sure it's a very easy fix.

Thanks.

t.
_______________________________________________
Wtr-general mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/wtr-general

Reply via email to