2014-09-29 100 views
0

我正在玩Ruby的Test::Unit::TestCase,儘管我的測試會運行,通過,失敗等。我沒有看到爲每個測試用例輸出的點。這是我需要設置的配置,還是我需要指定的冗長級別?Ruby:當我使用Test :: Unit運行測試時,爲什麼沒有點顯示?

我運行紅寶石2.1.0p0

僅供參考,這裏是我的工作的代碼。這是從銷燬所有的軟件截屏,其中的運動是從頭開始構建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] 
+0

默認情況下,它應該顯示傳球點,E代表錯誤,F代表失敗。你可以發佈你的輸出,也許你的測試之一,包括你的test_helper? – DiegoSalazar 2014-09-29 16:52:45

回答

0

運行的結果,我認爲一個TestCase代表單個測試。它不負責運行或提供UI。我認爲你正在尋找一名「亞軍」。 minitest,你可以簡單地require 'minitest/autorun',並在Test::Unit(這已棄用),你可能會以某種方式使用Test::Unit::Runner。我使用rspec,所以我不知道確切的細節,但Test :: Unit和minitest都包含在ruby stdlib中,因此文檔應該很容易找到。

0

我升級了'測試單元',我收回了點。在寫這個版本的時候是3.1.8。

相關問題