【问题标题】:Does minitest provide a "test" directive?minitest 是否提供“测试”指令?
【发布时间】:2016-07-13 13:15:13
【问题描述】:

在 Rails 中,我可以在测试中使用 test 关键字,我发现它非常有吸引力,并且是 Rspec 冗长的更好选择。

例子:

class TestMyClass < ActionController::TestCase
  test 'one equals one' do
    assert 1 == 1
  end
end

目前我正在创建一个 gem,我想在我的测试中采用相同的方法 - 使用 test 方法。我尝试从 Minitest 和 UnitTest 继承,后者似乎有效。但是我的印象是 Rails 使用 Minitest。那么Minitest 是否真的提供了test 指令?

这行得通:

class TestMyClass < Test::Unit::TestCase
  test 'one equals one' do
    assert 1 == 1
  end
end

这给了我“错误数量的测试参数”:

class TestMyClass < Minitest:Test
  test 'one equals one' do
    assert 1 == 1
  end
end

【问题讨论】:

    标签: ruby unit-testing minitest testunit


    【解决方案1】:

    不,Minitest 运行名称以“test_”开头的普通方法。

    来自 ActionController::TestCase 的方法 test 由 Rails 提供,用作“test_*”方法的简单包装。它转换了这个

    test 'truish' do
      assert true
    end
    

    到这里

    def test_truish
      assert true
    end
    

    它还会检查测试的主体是否已定义,如果未定义,则会显示错误消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-13
      • 2015-11-08
      • 2017-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-12
      相关资源
      最近更新 更多