【问题标题】:Why does Test::Unit.test_order= not working as expected?为什么 Test::Unit.test_order= 没有按预期工作?
【发布时间】:2012-06-25 08:04:01
【问题描述】:

有问题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

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

Started
:a
.:b
.:c
.

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

【问题讨论】:

  • 我知道这很明显,但我还是要指出:取决于运行测试的顺序,很可能意味着有问题。
  • @s.m.是的,我知道,我尽量避免。但有时我更喜欢得到一个预定义的顺序,所以我的更重要测试首先被测试。我可以使用方法名称对测试进行排序,但是我依赖于字母顺序。
  • 我同时发现了这个拉取请求:github.com/seattlerb/minitest/pull/122 有扩展,为什么它不是 MiniTest 的一部分。

标签: ruby unit-testing


【解决方案1】:

我发现了解决方案,或者更好的是我的错:

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=

【讨论】:

猜你喜欢
  • 2014-08-04
  • 2021-01-03
  • 2018-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-08
相关资源
最近更新 更多