I’m a bit new to ruby and test/unit so this may seem like a silly question, but I’m looking for a way to dynamically enter tests in to a template test case (order is important).
Basically I have a testcase that is similar to this:
Master TestCase file:
#testcase.rb
require 'test/unit/ui/console/testrunner'
require 'watir/testcase'
load "customTest1.rb"
class TC_Test_US < Watir::TestCase
def test_a
#do stuff
end
def test_b
#do stuff
end
#dynamically load website specific modules here
include myStuff
# end of custom tests carry on with generic tests
def test_y
#do stuff
end
def test_z
#do stuff
end
end
—
Custom TestCases
#customTest1.rb
module myStuff
def test_customTest1
#do stuff
end
def test_customTest2
#do stuff
end
end
Now I have several customTestX.rb files. Currently I duplicate my test_a to test_z in every file and this sucks when I need to change one or add a new one.
I want to be able to re-use the tests in the master test and just dynamically insert my custom tests in the middle (It’s important that test_b stay before my tests and test_y stay after my tests). I’d dynamically change the “load customTestX.rb” and keep the module named the same in each file.
When I launch this testcase like this I don’t get any errors, but none of my custom tests actually execute. The script skips from test_b to test_y and the customTest1 and customTest2 don’t get executed.
The answer probably lies in instancing off of my main testcase.rb, but I haven’t been successful in doing this yet. As soon as you load the master file it executes…. if I remove the testrunner require line I can’t load the file without exceptions. I’m not sure how I would insert my methods in the middle if I did this either. Any suggestions?
Thanks!!!
Your custom tests are not running since they do not start with the word “test”.
The “test” prefix is how Test::Unit knows which methods are tests vs regular methods. I believe Watir::TestCase is the same.
Try:
UPDATE – Use TestSuite:
I am not sure why your solution does not work, but one solution that looks like works would be to use a TestSuite. You could then call your starting test cases, your custom test cases and then your ending test cases.
The test suite:
Your starting tests:
Your ending tests:
Your custom middle tests: