本题属于zu test-unit 2.5.3版
测试单元版本 2.5.4 解决了问题
我有许多匿名测试用例的测试。它适用于测试单元 2.5.0,但实际版本 2.5.3 会产生错误。
当我运行这个测试时:
gem 'test-unit', ">=2.5.2"
require 'test/unit'
Class.new( Test::Unit::TestCase ) do
def test_add
assert_equal( 2, 1+1)
end
end
没有执行任何测试,并且出现错误undefined method sub' for nil:NilClass (NoMethodError)
(testrunner.rb:361
我使用实际的 test-unit-gem 2.5.3)。
使用 TestCase 的名称,问题就消失了:
gem 'test-unit'
require 'test/unit'
X = Class.new( Test::Unit::TestCase ) do
def test_add
assert_equal( 2, 1+1)
end
end
在我真正的问题中,我生成了许多测试用例。所以我有这样的情况:
gem 'test-unit'
require 'test/unit'
2.times {
X = Class.new( Test::Unit::TestCase ) do
def test_add
assert_equal( 2, 1+1)
end
end
}
如果我执行此操作,我会收到警告already initialized constant X
和错误:(
comparison of Array with Array failed (ArgumentError)
在 collector.rb:48:in sort_by' 中)。
我的问题:
- 我怎样才能避免错误?
- 或者:如何创建具有动态分配常量的测试用例?