2012-05-11 12 views
6

मैं एक गहरे लाल रंग का लिपि में 4 परीक्षण है, जो मैं आदेश का उपयोग कर समाप्त हो गया हैभागो कई रूबी टेस्ट यूनिट का उपयोग कर समानांतर में एक स्क्रिप्ट में परीक्षण

ruby test.rb 

बाहर डाल की तरह

Loaded suite test 
Started 
.... 

Finished in 50.326546 seconds. 

4 tests, 5 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 
100% passed 

लग रहा है क्या मैं प्राप्त करना चाहते हैं, अनुक्रमिक होने के बजाय समांतर में सभी 4 परीक्षण चलाएं। प्रत्येक 4 परीक्षणों की तरह कुछ थ्रेड की तरह कुछ, 4 परीक्षणों की धीमी गति से निष्पादन समय को प्रभावी ढंग से कम करता है + समांतर निष्पादन के कम समय।

मैं this पर आया, लेकिन ऐसा लगता है कि यह समानांतर में एकाधिक रूबी परीक्षण FILES चलाता है - कहें कि मेरे पास test1.rb, test2.rb test3.rb था, तो सभी तीन फाइलें समानांतर में चलती हैं।

किसी भी मदद की सराहना की जाएगी।

+0

मैं पुष्टि कर सकता है कि parallel_tests फ़ाइल स्तर पर काम करता है, जो नहीं है कि आप यहां क्या चाहते हैं, लेकिन यह क्या करता है पर बहुत अच्छा है। – x1a4

उत्तर

1

मैं TestSuite और Thread का एक संयोजन की कोशिश की:

gem 'test-unit' 
require 'test/unit' 
require 'test/unit/ui/console/testrunner' 
# we're running the tests, so we don't want Test::Unit to automatically run everything for us. See http://www.natontesting.com/2009/07/21/stop-rubys-testunit-suite-files-running-all-your-tests/ 
Test::Unit.run = true 


class MyTest < Test::Unit::TestCase 
    def test_1() 
    assert_equal(2, 1+1) 
    end 
    def test_2() 
    assert_equal(2, 4/2) 
    end 
    def test_3()  
    assert_equal(1, 3/2) 
    end 
    def test_4() 
    assert_equal(1.5, 3/2.0) 
    end 
end 

#create TestSuites. 
test_1 = Test::Unit::TestSuite.new("Test 1") 
test_1 << MyTest.new('test_1') 
#Same a bit shorter 
test_2 = Test::Unit::TestSuite.new("Test 2") << MyTest.new('test_2') 
test_3 = Test::Unit::TestSuite.new("Test 3") << MyTest.new('test_3') 
test_4 = Test::Unit::TestSuite.new("Test 4") << MyTest.new('test_4') 


#run the suites 
Thread.new{Test::Unit::UI::Console::TestRunner.run(test_1)} 
Thread.new{Test::Unit::UI::Console::TestRunner.run(test_2)} 
Thread.new{Test::Unit::UI::Console::TestRunner.run(test_3)} 
Thread.new{Test::Unit::UI::Console::TestRunner.run(test_4)} 

यह अच्छा लग रहा है, लेकिन मैं कोई बेंचमार्क परीक्षणों बनाया है।

आउटपुट (नीचे देखें) थोड़ा अराजक है, प्रत्येक धागा अपने संदेशों को अन्य धागे के संदेश में पोस्ट कर रहा है, लेकिन ऐसा लगता है कि यह सही काम करता है। तो बेहतर परीक्षण लॉग प्राप्त करने के लिए शायद आपको प्रत्येक थ्रेड के आउटपुट को पकड़ना होगा।

Loaded suite Test 4Loaded suite Test 1Loaded suite Test 2Loaded suite Test 3 
Started 
Started 
. 
Started 
. 
Started 

. 
. 
Finished in 0.328125 seconds. 

Finished in 0.328125 seconds. 




1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 
Finished in 0.765625 seconds. 
Finished in 0.546875 seconds. 
100% passed 
1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 



3.05 tests/s, 3.05 assertions/s 
100% passed 
1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 
1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications 

3.05 tests/s, 3.05 assertions/s 

100% passed 
100% passed 
+0

रूबी में धागे के लिए http://stackoverflow.com/questions/56087/does-ruby-have-real-multithreading भी देखें। – knut

+0

आपकी विस्तृत प्रतिक्रिया के लिए धन्यवाद। ऐसा लगता है जैसे यह काम करेगा, मैं अभी भी इस त्रुटि के साथ अटक गया हूँ। '/opt/local/lib/ruby/gems/1.8/gems/rake-0.9.2/lib/rake/ext/module.rb:36:in 'const_missing' में: अनियंत्रित निरंतर MyTest (NameError)' – Amey

+0

कभी भी ध्यान न रखें ! यह बहुत शानदार है! :) बहुत बहुत धन्यवाद – Amey

0

रूबी 1.9.3 में समानांतर में परीक्षण चलाने के लिए माना जाता है, लेकिन मुझे अभी तक काम करने के लिए यह नहीं मिला है।

0
gem install parallel_tests 

parallel_test a_test.rb b_test.rb 
+0

यह परीक्षणों को विभिन्न फाइलों में होने की आवश्यकता है –