並行して実行すると、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
また、OS X Snow leopard (ruby 2.0.0dev (2012-05-05 trunk 35543) [x86_64-darwin10.8.0]) で Ruby の最近のコミットを使用して最初のスクリプトを実行しましたが、そこでは機能しませんでした。
私は何を間違っていますか?
複数のファイルがあるが、明示的に使用しない場合、次のことが起こります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]