Ruby:Test :: Unit是否仍然存在?

时间:2014-11-24 07:14:21

标签: ruby unit-testing

我正在学习使用Ruby进行测试的codechool课程,他们正在使用Test::Unit。当我尝试require test/unit时虽然它说了以下内容:

Warning: you should require 'minitest/autorun' instead.
Warning: or add 'gem "minitest"' before 'require "minitest/autorun"'
From:
  /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/test/unit.rb:3:in `<top (required)>'
  test.rb:1:in `<main>'
MiniTest::Unit::TestCase is now Minitest::Test. From /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/test/unit/testcase.rb:8:in `<module:Unit>'
/

当我按照说明和require 'minitest/autorun',然后尝试运行我的测试时,它无法识别方法assert_equal

test.rb:5:in `<main>': undefined method `assert_equal' for main:Object (NoMethodError)

那么这个问题是什么?测试/单元不再存在吗?如果是这种情况,我该如何使用minitest运行测试? minitest是使用相同的语法还是完全不同?

1 个答案:

答案 0 :(得分:4)

Minitest是Test :: Unit的新名称。它完全兼容。您的语法仍适用于assert_equal

您需要将代码放入测试用例中。&#39;

示例:

require "minitest/autorun"

class TestMe < Minitest::Test

   def test_foo  # test methods must begin with "test_"
     assert_equal 1, 1
   end

end