我正在尝试Ruby和Unit测试,但我运行测试用例的简单尝试没有返回任何结果。奇怪的是,测试在运行之前运行,并返回运行的测试数量和断言的数量等等。但出于某种原因他们停止了跑步。我有两个分开的文件:
#TipoMovimento.rb
class TipoMovimento
attr_accessor :designacao
attr_accessor :cor
attr_accessor :regras
def initialize(aDesignacao, aCor, asRegras)
@designacao = aDesignacao
@cor = aCor
@regras = asRegras
end
def ==(other)
other.class == self.class && other.state == self.state
end
def state
self.instance_variables.map { |variable| self.instance_variable_get variable }
end
end和
#TesteTipoMovimento.rb
require './TipoMovimento.rb'
require 'test/unit'
class TesteTipoMovimento < Test::Unit::TestCase
def setup
@tm = TipoMovimento.new('Des1', 'Cor1', ['r1', 'r2'])
end
def tc_equal
tm2 = TipoMovimento.new('Des1', 'Cor1', ['r1', 'r2'])
assert_true(tm2 == @tm)
tm2 = TipoMovimento.new('Des2', 'Cor1', ['r1', 'r2'])
assert_false(tm2 == @tm)
end
end两个文件都在同一个文件夹中。不幸的是,当我运行测试文件时,什么都不会发生。按回车后,提示符就会忽略我的命令。类似于:
C:\My Ruby Files\>ruby TesteTipoMovimento.rb
C:\My Ruby Files\>这显然是一件很简单的事情,我错过了,所以如果有人能帮我,我会很感激。谢谢!
发布于 2016-10-30 18:31:14
你在那个测试类里没有考试。若要使方法成为测试,请在其名称前加上test_。
class TesteTipoMovimento < Test::Unit::TestCase
def setup
@tm = TipoMovimento.new('Des1', 'Cor1', ['r1', 'r2'])
end
def test_tc_equal
tm2 = TipoMovimento.new('Des1', 'Cor1', ['r1', 'r2'])
assert_true(tm2 == @tm)
tm2 = TipoMovimento.new('Des2', 'Cor1', ['r1', 'r2'])
assert_false(tm2 == @tm)
end
endhttps://stackoverflow.com/questions/40332226
复制相似问题