为什么Test :: Unit.test_order =没有按预期工作?

时间:2012-06-25 08:04:01

标签: ruby unit-testing

问题为In Ruby, how to I control the order in which Test::Unit tests are run?,我想回答test_order = :defined

documentation for Test::Unit::TestCase.test_order说:

  

设置当前测试顺序。

     

以下是可用订单:

     
      
  • :字母   默认。测试按字母顺序排序。
  •   
  • :随机   测试按随机顺序排序。
  •   
  • :定义   测试按定义的顺序排序。
  •   

所以我认为这将按照方法定义的顺序执行测试:

gem 'test-unit'
require 'test/unit'
class Mytest < Test::Unit::TestCase
  test_order = :defined
  #~ test_order = :random
  #~ test_order = :alphabetic #default
  def test_b
    p :b
  end
  def test_a
    p :a
  end
  def test_c
    p :c
  end
end

但是当我执行它(用测试单元2.4.9和2.5测试)时,我得到了字母顺序:

Started
:a
.:b
.:c
.

有什么问题?我的代码中是否缺少某些内容,文档是错误的还是存在错误?

1 个答案:

答案 0 :(得分:3)

我检测到了解决方案,或者更好的是我的错误:

gem 'test-unit'
require 'test/unit'
class Mytest < Test::Unit::TestCase
  self.test_order = :defined
  #~ self.test_order = :random
  #~ self.test_order = :alphabetic #default
  def test_b
    p :b
  end
  def test_a
    p :a
  end
  def test_c
    p :c
  end
end

区别:我在课堂上使用了test_order = :defined。 发生了什么:创建了一个局部变量test_order

使用self.test_order = :defined调用方法test_order=

相关问题