使用Buildr运行Ruby单元测试

时间:2022-10-15 20:29:42

I am using buildr for some time now, but today I came over a little problem in connection to unit testing of ruby code.

我现在使用buildr一段时间了,但是今天我遇到了与ruby代码的单元测试有关的一个小问题。

So in my buildfile I have these lines:

所以在我的构建文件中我有这些行:

define "ruby-project" do

    project.version = VERSION_NUMBER
    project.group = GROUP

    Rake::TestTask.new(:test_rb) do |t|
        t.warning = true
        t.verbose = true
        t.test_files = FileList['test/*.rb']
    end
    task test => [:test_rb]

end

running buildr test actually runs the tests, what is nice. The test is actually just that:

运行buildr测试实际上运行测试,什么是好的。测试实际上只是:

require 'test/unit'

class TestFileParse < Test::Unit::TestCase
    def test_fail
        assert(false, 'test to fail')
     end
end

As expected it fails, BUT what is strange for me is that buildr quits the build with that message:

正如所料,它失败了,但令我感到奇怪的是,buildr使用该消息退出构建:

sh: 2: Syntax error: Unterminated quoted string
Buildr aborted!
RuntimeError : Command failed with status (1): [/usr/bin/ruby1.9.1 -w -I"lib" -I"/var/lib/...]

Running ruby file-with-failing-test-from-above.rp does not throw a runtime error, instead it prints the test report on screen, what is what is what I want.

运行ruby file-with-faileding-test-from-above.rp不会抛出运行时错误,而是在屏幕上打印测试报告,这是我想要的。

Question

How can I make Buildr run the unit tests without quitting with an RuntimeError if a test fails?

如果测试失败,如何使Buildr运行单元测试而不退出RuntimeError?

Greetings Philipp

问候菲利普

1 个解决方案

#1


0  

Since I am not too familiar with Ruby development, what involves Rake, I was looking for the wrong question. Instead of looking for: »how to run unit test with buildr«, the question should have been »how to run unit tests with rake«, because buildr is a kind of extended Rake (similar to the »maven-ant-relationship«). So everything one can do in Rake, one can do in buildr, too. Therefore on good SO answer to run ruby unit tests in buildr is here.

由于我不太熟悉Ruby开发,涉及Rake的内容,我一直在寻找错误的问题。而不是寻找:»如何使用buildr«运行单元测试,问题应该是»如何使用rake«运行单元测试,因为buildr是一种扩展的Rake(类似于»maven-ant-relationship«) 。所以在Rake中你可以做的一切,也可以在buildr中做。因此,在良好的SO上,在buildr中运行ruby单元测试的答案就在这里。

Additionally it is possible to run RSpec's with buildr, therefore one has two options:

此外,可以使用buildr运行RSpec,因此有两个选项:

  1. set project.test.using :rspec, what involves the use of JRuby, so one has to set JRUBY_HOME (in my case ~/.rvm/rubies/jruby-1.7.9/), or run buildr within jruby. In my case this slowed test execution down, because each time a jvm needed to be started.
  2. 设置project.test.using:rspec,涉及JRuby的使用,所以必须设置JRUBY_HOME(在我的情况下〜/ .rvm / rubies / jruby-1.7.9 /),或者在jruby中运行buildr。在我的情况下,这减慢了测试执行速度,因为每次需要启动一个jvm。
  3. Or one can use rspec's rake task in this manner. I choose this method since my tests run much faster without the jvm overhead.
  4. 或者可以用这种方式使用rspec的rake任务。我选择这种方法,因为我的测试运行得更快,没有jvm开销。

n.b. as the answer implies, I switched over to rspec.

注:如答案所示,我切换到了rspec。

Happy Testing/Speccing!

快乐测试/指定!

#1


0  

Since I am not too familiar with Ruby development, what involves Rake, I was looking for the wrong question. Instead of looking for: »how to run unit test with buildr«, the question should have been »how to run unit tests with rake«, because buildr is a kind of extended Rake (similar to the »maven-ant-relationship«). So everything one can do in Rake, one can do in buildr, too. Therefore on good SO answer to run ruby unit tests in buildr is here.

由于我不太熟悉Ruby开发,涉及Rake的内容,我一直在寻找错误的问题。而不是寻找:»如何使用buildr«运行单元测试,问题应该是»如何使用rake«运行单元测试,因为buildr是一种扩展的Rake(类似于»maven-ant-relationship«) 。所以在Rake中你可以做的一切,也可以在buildr中做。因此,在良好的SO上,在buildr中运行ruby单元测试的答案就在这里。

Additionally it is possible to run RSpec's with buildr, therefore one has two options:

此外,可以使用buildr运行RSpec,因此有两个选项:

  1. set project.test.using :rspec, what involves the use of JRuby, so one has to set JRUBY_HOME (in my case ~/.rvm/rubies/jruby-1.7.9/), or run buildr within jruby. In my case this slowed test execution down, because each time a jvm needed to be started.
  2. 设置project.test.using:rspec,涉及JRuby的使用,所以必须设置JRUBY_HOME(在我的情况下〜/ .rvm / rubies / jruby-1.7.9 /),或者在jruby中运行buildr。在我的情况下,这减慢了测试执行速度,因为每次需要启动一个jvm。
  3. Or one can use rspec's rake task in this manner. I choose this method since my tests run much faster without the jvm overhead.
  4. 或者可以用这种方式使用rspec的rake任务。我选择这种方法,因为我的测试运行得更快,没有jvm开销。

n.b. as the answer implies, I switched over to rspec.

注:如答案所示,我切换到了rspec。

Happy Testing/Speccing!

快乐测试/指定!