I want to organize multiple tests in the same file. And run them as single tests later.
Example:tests/TC_release1.rb
- the test file with like 10 tests in it
ruby tests/TC_release1.rb --name test_TC_01
- to run a single test
All the tests from the test file will be initialized (in my case 10 times). This is because of the "call order" described in the docs in http://test-unit.github.io/test-unit/en/Test/Unit/TestCase.html
Question:How can I avoid that, and run it in stand-alone mode?
The test file$ cat tests/TC_release1.rb
require 'rubygems'
require 'date'
require 'test/unit'
class TC_release1 < Test::Unit::TestCase
def initialize(options)
super
puts DateTime.now.strftime("%Y-%m-%dT%H:%M:%S")+" Hello from the init method."
end
def test_TC_01()
puts DateTime.now.strftime("%Y-%m-%dT%H:%M:%S")+" Start test 01"
assert_match(/2017/, `date /T`)
puts DateTime.now.strftime("%Y-%m-%dT%H:%M:%S")+" End test 01"
end
def test_TC_02()
assert_match(/2017/, `date /T`)
end
def test_TC_03()
assert_match(/2017/, `date /T`)
end
def test_TC_04()
assert_match(/2017/, `date /T`)
end
def test_TC_05()
assert_match(/2017/, `date /T`)
end
def test_TC_06()
assert_match(/2017/, `date /T`)
end
def test_TC_07()
assert_match(/2017/, `date /T`)
end
def test_TC_08()
assert_match(/2017/, `date /T`)
end
def test_TC_09()
assert_match(/2017/, `date /T`)
end
def test_TC_10()
assert_match(/2017/, `date /T`)
end
end
Execute just the first test case from the test file
$ ruby tests/TC_release1.rb --name test_TC_01
2017-09-13T00:31:16 Hello from the init method.
2017-09-13T00:31:16 Hello from the init method.
2017-09-13T00:31:16 Hello from the init method.
2017-09-13T00:31:16 Hello from the init method.
2017-09-13T00:31:16 Hello from the init method.
2017-09-13T00:31:16 Hello from the init method.
2017-09-13T00:31:16 Hello from the init method.
2017-09-13T00:31:16 Hello from the init method.
2017-09-13T00:31:16 Hello from the init method.
2017-09-13T00:31:16 Hello from the init method.
Loaded suite tests/TC_release1
Started
2017-09-13T00:31:16 Start test 01
2017-09-13T00:31:16 End test 01
.
Finished in 0.048923 seconds.
--------------------------------------------------------------------------------------------------------------------------------------------------------
1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
--------------------------------------------------------------------------------------------------------------------------------------------------------
20.44 tests/s, 20.44 assertions/s
Ok, will be using
setup
hook as suggested by phoet.Thanks.