Ruby:为什么在使用Test :: Unit运行测试时没有显示点?

时间:2014-09-29 16:44:44

标签: ruby unit-testing

我正在玩Ruby Test::Unit::TestCase,虽然我的测试会运行,通过,失败等等。我没有看到每个测试用例输出的点数。这是我需要设置的配置,还是我需要指定的详细程度?

我正在运行Ruby 2.1.0p0

供参考,这是我正在使用的代码。它是来自Destroy All Software的截屏视频,其中练习是从头开始构建rspec(当然不是全部):

测试:

#test_spec.rb

require 'test/unit'
require_relative 'spec'


class TestDescribe < Test::Unit::TestCase
  def test_that_it_can_pass
    describe 'some thing' do
      it 'has some property' do
      end
    end
  end

  def test_that_it_can_fail
    assert_raise(IndexError) do
      describe 'some failing thing' do 
        it 'fails' do
          raise IndexError
        end
      end
    end
  end
end


class TestAssertion < Test::Unit::TestCase
  def test_that_it_can_pass
    2.should == 2
  end

  def test_that_it_can_fail
    assert_raise(AssertionError) do
      1.should == 2
    end
  end
end

代码:

#spec.rb

def describe(description, &block)
  ExampleGroup.new(block).evaluate!
end


class ExampleGroup
  def initialize(block)
    @block = block
  end

  def evaluate!
    instance_eval(&@block)
  end

  def it(description, &block)
    block.call
  end
end


class Object
  def should
    DelayedAssertion.new(self)
  end
end

class DelayedAssertion
  def initialize(subject)
    @subject = subject
  end

  def ==(other)
    raise AssertionError unless @subject == other
  end
end


class AssertionError < Exception
end

使用ruby test_spec.rb

运行时的输出
Run options:

# Running tests:

Finished tests in 0.004410s, 907.0295 tests/s, 453.5147 assertions/s.
4 tests, 2 assertions, 0 failures, 0 errors, 0 skips

ruby -v: ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin12.0]

2 个答案:

答案 0 :(得分:0)

我认为TestCase代表一次测试。它不负责运行或提供UI。我想你正在寻找一个“跑步者”。在minitest中,您可以简单require 'minitest/autorun',在Test::Unit(已弃用)中,您可能会以某种方式使用Test::Unit::Runner。我使用rspec所以我不知道确切的细节,但是Test :: Unit和minitest都包含在ruby stdlib中,因此文档应该很容易找到。

答案 1 :(得分:0)

我升级了'测试单元',我得到了回报。在撰写本文时,版本为3.1.8。