2

并行运行时,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 snow leopard (ruby 2.0.0dev (2012-05-05 trunk 35543) [x86_64-darwin10.8.0]) 运行了第一个脚本,但它在那里不起作用。

我究竟做错了什么?

当我有多个文件但未明确使用时会发生以下情况Test::Unit::Runner

测试1.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]
4

1 回答 1

3

我是 sora_h 的维护者test/unit

test/unit为每个测试文件并行化。

您需要分离测试文件并TestCase进行并行化。

很抱歉给您带来不便,但我们无法为每个test_*方法并行化,因为有些test_*方法不能单独运行。(需要订购)

您可以使用Test::Unit::Runner来运行多个文件。

谢谢你。

于 2012-05-19T01:23:03.173 回答