On Thu, Mar 29, 2007 at 06:23:14AM +0900, Matt Berney wrote:
> I have a test case, based on the Test::Unit::TestCase. How does one pass
> data to the test in such a way that the test can be run multiple times
> with different input.
> 
> For example:
> 
> class TC_CreateOrder < Test::Unit::TestCase
>   def test_NewOrder
>     assert "order successful"
>   end
> end
> 
> Now, I want to be able to generate a new order for various order types,
> (TYPE1, TYPE2, TYPE3, etc.)
> 
> class TS_OrderTests
>   def self.suite
>     suite = Test::Unit::TestSuite.new
>     suite << TC_CreateOrder.suite # TYPE1 goes here
>     suite << TC_CreateOrder.suite # TYPE2 goes here
>     suite << TC_CreateOrder.suite # TYPE3 goes here
>     return suite
>   end
> end
> 
> Test::Unit::UI::Console::TestRunner.run(TS_OrderTests)

If it's only one test method, you can factor it out in the class:

class TC_CreateOrder < Test::Unit::TestCase
  def do_test(t)
    .. process t
  end

  def test_type1
    do_test(TYPE1)
  end

  def test_type2
    do_test(TYPE2)
  end

  def test_type3
    do_test(TYPE3)
  end
end

Otherwise, how about:

class TC_CreateOrder1 < TC_CreateOrder
  FIXTURE = TYPE1
end

class TC_CreateOrder2 < TC_CreateOrder
  FIXTURE = TYPE2
end

class TC_CreateOrder3 < TC_CreateOrder
  FIXTURE = TYPE3
end

(I'm not sure how you'd prevent the base test TC_CreateOrder being run)

Regards,

Brian.