I've inherited a large suite of Test::Unit tests, and one of my first tasks is to have the suite run to completion rather than exit after the first test failu开发者_C百科re.
I'm currently rescuing AssertionFailedError
and ensuring an output string, but this just seems wrong. What's the better way? Seems like it would be a configuration option.
Some more background would be helpful. I can't say I understand the behavior you're seeing.
I'm using both the core test/unit lib that comes with ruby 1.8, as well as several versions of the gem with ruby 1.9. The normal behavior for both of these is to run the entire loaded suite to completion and summarize the results.
Running a script that says require 'test/unit'
will add an on-exit hook to run Test::Unit::AutoRunner
with a Test::Unit::Collector::ObjectSpace
collector (i.e. runs every instance of Test::Unit::TestCase
currently loaded in the global object space).
It's also fairly easy to write your own custom test runner which manually loads your test classes and packs them into a Test::Unit::TestSuite
, and capture its results.
But with every version of test/unit I've used, I've always seen the entire suite finish and report both failures and errors. In lieu of further info, I'd suggest experimenting with a single dummy test so see how you should expect test/unit to behave.
For example
require 'test/unit'
class Foo < Test::Unit::TestCase
def testFoo
flunk 'bad foo'
end
end
class Bar < Test::Unit::TestCase
def testBar
raise 'bar bar'
end
end
gives
Loaded suite foo
Started EF Finished in 0.001000 seconds.
1) Error:
testBar(Bar)
RuntimeError: bad bar
foo.rb:9:in `testBar`
2) Failure:
testFoo(Foo) [foo.rb:4]:
bad foo
2 tests, 1 assertions, 1 failures, 1 errors, 0 skips
Lastly: where are you trying to rescue/ensure? In the test methods? Under normal circumstances, there's no reason to catch an AssertionFailedError. This is for Test::Unit::TestCase
to do, as a way to count failures and give you the report you want. Catching this interferes with what test/unit is written to do.
精彩评论