我有一个项目,在jruby中使用自编宝石(使用rvm在jrubies之间切换)。使用jruby-1.7.0,我可以使用Test :: Unit :: TestCase进行测试。现在我已经在jruby-1.7.13中切换到MiniTest。但是我不能再通过“rake test'”来运行我的测试。
错误就像是...... Mocha :: ExpectationError:意外调用:blabla.new()...用blabla beeing my jruby class
仅当我通过TEST =和TESTOPTS =参数运行它们才能使用单个测试文件并通过--name =(使用正则表达式)选择一个或视图测试时,它才有效。
我使用
的帮助文件require 'minitest/spec'
require 'minitest/autorun'
require 'mocha/integration'
class MiniTest::Test
end
而不是用于旧测试套件Test :: Unit :: TestCase
的行require 'test/unit'
require 'shoulda'
require 'mocha'
class Test::Unit::TestCase
end
MiniTest的主要区别在于测试订单。因此,我试图通过定义test_order来规避随机化,如
class MiniTest::Test
def test_order
:alpha
end
end
这对测试订单没有影响,但这真的是一个问题吗?在测试套件中也可能出现错误。这是一个错误吗?请帮忙!
您也可以查看 require self made gem in jruby fails after update to jruby-1.7.13 对于我已经可以解决负载问题的先前帖子。
答案 0 :(得分:0)
这是一些代码
require File.dirname(__FILE__) + "/../helper.rb"
require 'command/flow_control_command'
## --seed=36725
module Command
class TestFlowControlCommand < MiniTest::Test
def setup
fcp = Configuration::FlowControlParameter.last
fcp.number_ports = 16
fcp.save!
end
def test_should_exist
assert FlowControlCommand
end
def test_should_initialize
FlowControlCommand.expects(:new).with("modbus").returns(true)
assert FlowControlCommand.new("modbus")
end
def test_should_have_constants
assert_equal [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0], FlowControlCommand::CIRCLE
end
def test_should_find_line_1
result = FlowControlCommand.new("modbus").find_line [1,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 1,1,0,0, 0,0]
assert_equal "LINE1", result
end
def test_should_not_find_line
result = FlowControlCommand.new("modbus").find_line [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 1,1,0,0, 0,0]
assert_equal "LINE?", result
result = FlowControlCommand.new("modbus").find_line [1,1,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, 1,1,0,0, 0,0]
assert_equal "LINE?", result
end
def test_should_find_line_16
result = FlowControlCommand.new("modbus").find_line [0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1, 1,1,0,0, 0,0]
assert_equal "LINE16", result
end
def test_should_find_line_13
result = FlowControlCommand.new("modbus").find_line [0,0,0,0, 0,0,0,0, 0,0,0,0, 1,0,0,0, 1,1,0,0, 0,0]
assert_equal "LINE13", result
end
+ some more tests
运行此操作将导致
..... EEEEE.EEE。
以1.036000s完成,14.4788次/秒,2.8958次断言/次。
1)错误: 命令:: TestFlowControlCommand#test_should_find_line_circle: Mocha :: ExpectationError:意外调用:Command :: FlowControlCommand.new('modbus') 不满意的期望: - 预计只调用一次,调用两次:Command :: FlowControlCommand.new('modbus')
/home/frank/Rubymineprojects/ndir_med1/dibta-model/test/command/test_flow_control_command.rb:61:in`test_should_find_line_circle'
2)错误: 命令:: TestFlowControlCommand#test_should_find_line_14: Mocha :: ExpectationError:意外调用:Command :: FlowControlCommand.new('modbus') 不满意的期望: - 预计恰好一次,调用3次:Command :: FlowControlCommand.new('modbus')
/home/frank/Rubymineprojects/ndir_med1/dibta-model/test/command/test_flow_control_command.rb:46:in`test_should_find_line_14'
如果我逐个运行测试没有错误发生,如果我使用specail种子参数运行,测试也会运行。