Phlip
2/6/2008 2:25:00 PM
Mario Ruiz wrote:
> I have a few classes containing a few tescase methods. I would like to
> create a new class in order to run different tescases methods of
> different classes:
Why?
Yes there are reasons, but generally test cases should not be reusable.
Push whatever code you need to reuse into "helper" classes, and inherit
these into your test cases, as raw functions, not test cases.
module MyTestStuff
def test01_example
# reuse an entire case here
end
def assemble_example
# reuse the code that assembles your test targets here
@assembly = whatever
end
def assert_example
# reuse your application-specific assertion here
end
end
class Myclass2 < Test::Unit::Testcase
include MyTestStuff
def setup
assemble_example
end
def test01_example
assert 42 == @assembly
end
def test02_example
assert_example
end
end # this will also run test01_example
> def test01_beep
>
> require 'testcases/myclass1'
> Myclass1.new().test03_example()
> Myclass1.new().test01_example()
>
> require 'testcases/myclass2'
> Myclass2.new().test01_example()
Okay, why?
If you reeally need to do that (I can't think of a reason that doesn't
lead to coupling your code), then include MyTestStuff, and just call into
the whole list directly:
test03_example()
test01_example()
test01_example()
(Also, google for "assert 2.0", to help simplify your assertions. It
folds all the minor variations, such as assert_equal, assert_match, into
one powerful assert{ anything }.)
--
Phlip