加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-17 02:18:14 所属栏目:百科 来源:网络整理
导读:有一个问题 In Ruby,how to I control the order in which Test::Unit tests are run?,想要回答一下对test_order =:的定义, documentation for Test::Unit::TestCase.test_order 说: Sets the current test order. Here are the available order: :alphabe
有一个问题 In Ruby,how to I control the order in which Test::Unit tests are run?,想要回答一下对test_order =:的定义,

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

Sets the current test order.

Here are the available order:

  • :alphabetic
    Default. Tests are sorted in alphabetic order.
  • :random
    Tests are sorted in random order.
  • :defined
    Tests are sorted in defined 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
.

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

解决方法

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

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 =:在我的课程中定义.
发生了什么:创建了一个局部变量test_order.

使用self.test_order =:定义了调用方法test_order =.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读