当并行运行时,Ruby 1.9.3不运行任何单元测试
鉴于以下代码,
# Modified from https://gist.github.com/1334056/121396125ca4dd7ee1bb81536cce0754700f20fb
# replication.rb
require 'test/unit'
class TestTest < Test::Unit::TestCase
def test_one
assert true
end
def test_two
assert true
end
end
单元测试在不并行运行时工作,但在并行运行时不起作用:
$ ruby1.9.1 replication.rb
Run options:
# Running tests:
..
Finished tests in 0.000348s, 5740.7094 tests/s, 5740.7094 assertions/s.
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
$ ruby1.9.1 replication.rb --jobs=2 --ruby /usr/bin/ruby1.9.1
Run options: --jobs=2 --ruby /usr/bin/ruby1.9.1
# Running tests:
Retrying...
Finished tests in 0.039012s, 0.0000 tests/s, 0.0000 assertions/s.
0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
对于它的价值,这是调试开关打开时发生的情况:
$ export RUBYOPT="-d"
$ ruby1.9.1 replication.rb
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1243 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1252 - cannot load such file -- rubygems/defaults/ruby
Run options:
# Running tests:
..
Finished tests in 0.000350s, 5718.3539 tests/s, 5718.3539 assertions/s.
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
$ ruby1.9.1 replication.rb --jobs=2 --ruby /usr/bin/ruby1.9.1
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1243 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1252 - cannot load such file -- rubygems/defaults/ruby
Run options: --jobs=2 --ruby /usr/bin/ruby1.9.1
# Running tests:
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1243 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1252 - cannot load such file -- rubygems/defaults/ruby
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1243 - cannot load such file -- rubygems/defaults/operating_system
Exception `LoadError' at /usr/lib/ruby/1.9.1/rubygems.rb:1252 - cannot load such file -- rubygems/defaults/ruby
/usr/lib/ruby/1.9.1/test/unit/parallel.rb:149: warning: method redefined; discarding old on_parallel_worker?
/usr/lib/ruby/1.9.1/test/unit/testcase.rb:11: warning: previous definition of on_parallel_worker? was here
/usr/lib/ruby/1.9.1/test/unit/parallel.rb:149: warning: method redefined; discarding old on_parallel_worker?
/usr/lib/ruby/1.9.1/test/unit/testcase.rb:11: warning: previous definition of on_parallel_worker? was here
Exception `Errno::EPIPE' at /usr/lib/ruby/1.9.1/test/unit/parallel.rb:125 - Broken pipe - <STDOUT>
Exception `Errno::EPIPE' at /usr/lib/ruby/1.9.1/test/unit/parallel.rb:133 - Broken pipe - <STDOUT>
Retrying...
Finished tests in 0.033203s, 0.0000 tests/s, 0.0000 assertions/s.
0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
我也尝试过要求minitest,但是没有并行测试可用:
# mini_me.rb
# modified from http://apidock.com/ruby/MiniTest
require 'minitest/autorun'
class TestMeme < MiniTest::Unit::TestCase
def test_one
assert true
end
def test_two
assert true
end
end
给出
$ ruby1.9.1 mini_me.rb --help
minitest options:
-h, --help Display this help.
-s, --seed SEED Sets random seed
-v, --verbose Verbose. Show progress processing files.
-n, --name PATTERN Filter test names on pattern.
这是Ruby和ubuntu的版本。
$ ruby1.9.1 --version
ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-linux]
$ uname -a
Linux [redacted] 3.2.0-24-generic #37-Ubuntu SMP Wed Apr 25 08:43:22 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
我还使用最新提交的Ruby on OS X雪豹(ruby 2.0.0dev(2012-05-05 trunk 35543)[x86_64-darwin10.8.0])运行第一个脚本,但它没有在那里工作。
我做错了什么?
如果我有多个文件,但未明确使用Test::Unit::Runner
test1.rb
require "test/unit"
class Test1 < Test::Unit::TestCase
def test_one
assert true
end
end
test2.rb
require "test/unit"
class Test2 < Test::Unit::TestCase
def test_two
assert true
end
end
test_all.rb
require_relative "test1"
require_relative "test2"
尝试使用这种方法:
$ ruby test_all.rb --basedir=. --jobs 2 --ruby /Users/agrimm/.rvm/rubies/ruby-head/bin/ruby
Run options: --basedir=. --jobs 2 --ruby /Users/agrimm/.rvm/rubies/ruby-head/bin/ruby
# Running tests:
Retrying...
Finished tests in 0.075256s, 0.0000 tests/s, 0.0000 assertions/s.
0 tests, 0 assertions, 0 failures, 0 errors, 0 skips
ruby -v: ruby 2.0.0dev (2012-05-05 trunk 35543) [x86_64-darwin10.8.0]
答案 0 :(得分:3)
我是sora_h test/unit
的维护者。
test/unit
并行化。
您需要将测试文件与TestCase
分开并行化。
很抱歉给您带来不便,但我们无法对每种test_*
方法进行并行化,因为有些test_*
方法无法单独运行。 (需要订购)
您可以使用Test::Unit::Runner
来运行多个文件。
谢谢。