Ruby测试不运行

时间:2016-10-30 18:28:38

标签: ruby unit-testing

我正在尝试使用Ruby和单元测试,但我在运行测试用例时的简单尝试却没有返回任何内容。奇怪的是,测试在之前运行并返回运行的测试数和断言数等。但出于某种原因,他们停止了跑步。我有两个独立的文件:

#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\>

这显然是我想念的简单事情,所以如果有人能帮助我,我会很感激。谢谢!

1 个答案:

答案 0 :(得分:1)

您在该测试类中没有测试。要使方法成为测试,请在其名称前加上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
end