Imagine I have a test like this:
class MyUnitTest < Test::Unit::TestCase
def test_first
# test code here
end
def test_second
# test code here
end
def test_third
# test code here
end
end
My test cases are destructive, and I need to regenerate the input in between tests. Therefore, it would be useful to run only one test case at a time. Currently, my approach is to comment tests that I don't want executed, but surely there must be a better way?
So, for example, how do I run only test_first when I execute my test?
Use --name PATTERN argument in order to filter out test names you want to run.
D:\Projects>ruby test.rb
Loaded suite test
Started
...
Finished in 0.000000 seconds.
3 tests, 0 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 39768
D:\Projects>ruby test.rb -n test_first
Loaded suite test
Started
.
Finished in 0.000000 seconds.
1 tests, 0 assertions, 0 failures, 0 errors, 0 skips
Test run options: --seed 53891 --name "test_first"
Can you regenerate the input with ruby? Then you could use the setup-method.
gem 'test-unit', '>= 2.1.1' #startup
require 'test/unit'
class Test_setup < Test::Unit::TestCase
def setup
#Your regeneration of the input
puts "Setup"
end
def teardown
#Clean actions
puts "End"
end
def test_1()
puts "Testing setup 1"
end
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With