[英]How can I test only a method with Ruby's Test::Unit?
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? 那么,例如,在执行测试时如何仅运行test_first
?
Use --name PATTERN
argument in order to filter out test names you want to run. 使用--name PATTERN
参数可以过滤掉要运行的测试名称。
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? 你能用ruby重新生成输入吗? Then you could use the setup-method. 然后你可以使用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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.