On Jul 15, 3:19 pm, David M. [email protected] wrote:
...
cases at run time. What I think I need to do is something like this
Thanks in advance
David M.
I took the following test:
require ‘test/unit/ui/console/testrunner’
require “test/unit”
class TestCases < Test::Unit::TestCase
def test_case_1
p “case 1”
end
end
eval “class TestCase2 < TestCases;def test_case_2;p ‘case 2’;end;end;”
Test::Unit::UI::Console::TestRunner.run(TestCases)
Test::Unit::UI::Console::TestRunner.run(TestCase2)
It gives:
Loaded suite TestCases
Started
“case 1”
.
Finished in 0.000433 seconds.
1 tests, 0 assertions, 0 failures, 0 errors
Loaded suite
Started
“case 1”
.“case 2”
.
Finished in 0.001912 seconds.
2 tests, 0 assertions, 0 failures, 0 errors
It works well.and following is the same
require ‘test/unit/ui/console/testrunner’
require “test/unit”
class TestCases < Test::Unit::TestCase
def test_case_1
p “case 1”
end
end
test_case_2 = Class.new(TestCases) do
def test_case_2
p “case 2”
end
end
Test::Unit::UI::Console::TestRunner.run(TestCases)
Test::Unit::UI::Console::TestRunner.run(test_case_2)
if you take a look into the testcase.rb
def initialize(test_method_name)
so,I wrote the following code:
require ‘test/unit/ui/console/testrunner’
require “test/unit”
class TestCases < Test::Unit::TestCase
def test_case_1
p “case 1”
end
def test_case_2
p “case 2”
end
end
test_case_2 = TestCases.new(:test_case_2)
Test::Unit::UI::Console::TestRunner.run(TestCases)
Test::Unit::UI::Console::TestRunner.run(test_case_2)
the result:
Loaded suite TestCases
Started
“case 1”
.“case 2”
.
Finished in 0.00051 seconds.
2 tests, 0 assertions, 0 failures, 0 errors
Loaded suite test_case_2(TestCases)
Started
“case 2”
.
Finished in 0.000314 seconds.
1 tests, 0 assertions, 0 failures, 0 errors
so the initialize function takes a methods name,and only the method is
running if you run the instance
but if you run the Class,the test* methods will all run through the
TestCase.suite [testcase.rb]
I hope this will help