gpt4 book ai didi

ruby 单元测试错误 : "you should require ' minitest/autorun' instead.“

转载 作者:数据小太阳 更新时间:2023-10-29 08:19:58 24 4
gpt4 key购买 nike

我从 http://en.wikibooks.org/wiki/Ruby_Programming/Unit_testing 复制了一个非常简单的单元测试.

require_relative "simple_number"
require "test/unit"

class TestSimpleNumber < Test::Unit::TestCase

def test_simple
assert_equal(4, SimpleNumber.new(2).add(2) )
assert_equal(6, SimpleNumber.new(2).multiply(3) )
end

end

执行这段代码会导致错误:

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)>'
tc_simple_number.rb:5: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>'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/test/unit.rb:670:in `<class:Runner>': undefined method `_run_suite' for class `Test::Unit::Runner' (NameError)
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/test/unit.rb:255:in `<module:Unit>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/test/unit.rb:9:in `<module:Test>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/test/unit.rb:8:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from tc_simple_number.rb:5:in `<main>'

可能出了什么问题?

最佳答案

Test::Unit::TestCase 已弃用,取而代之的是 Minitest::Test。如果你想让你的例子工作,你需要改变一些东西:

  • require "test/unit" 替换为 require "minitest/autorun"
  • Test::Unit::TestCase 替换为Minitest::Test

关于 ruby 单元测试错误 : "you should require ' minitest/autorun' instead.“,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28597971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com