【发布时间】:2014-09-29 16:44:43
【问题描述】:
我在玩 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]
【问题讨论】:
-
默认情况下,它应该显示点表示通过,E 表示错误,F 表示失败。你能发布你的输出,也许你的测试之一,包括你的 test_helper?
标签: ruby unit-testing