3

想象一下我有一个这样的测试:

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

我的测试用例具有破坏性,我需要在测试之间重新生成输入。因此,一次只运行一个测试用例会很有用。目前,我的方法是评论我不想执行的测试,但肯定有更好的方法吗?

因此,例如,如何仅test_first在执行测试时运行?

4

2 回答 2

3

使用--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"
于 2011-08-08T10:31:30.820 回答
2

你能用 ruby​​ 重新生成输入吗?然后你可以使用设置方法。

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
于 2011-08-08T13:30:00.643 回答