Re: [Perlunit-users] How to exit from test suite?
Status: Beta
Brought to you by:
mca1001
From: Matthew A. <mc...@us...> - 2003-10-13 19:36:47
|
On Sat, Oct 04, 2003 at 01:16:08PM +0400, Dmitry Diskin wrote: > If one of my tests fail, One particular test, or any of them? Tests are often considered to be independent, at least to a large extent. > other tests should not be executed. In order to stop execution, I > use the following code: > > sub test_001_load { On the choice of method name, is the numbering just for convenience or were you relying on one test's side-effects to do something for the next one? The manpage for Test::Unit::TestCase (notes section) talks about this a bit. > my $self = shift; > if ($loaded_nok) { > $self->fail("Unrecoverable error, can't continue."); > exit; > } > } I haven't done anything like this with perlunit, but in JUnit running from an Ant file, I have put aside a set of tests to run first. They check things like the presence of the database we're just about to run the hundred tests against - 100 failures aren't very useful. You could do this by generating test suites by some means and having a more customised testrunner script. > Is it a proper way? Is there any $suite->stop method? Hmm, there's a Test::Unit::Result->stop() which would appear to do what you want. I'm not sure what the proper answer is, and I don't claim to have read the docs recently. 8-} You'd need to get the 'result' object from the 'suite' which creates it. $testrunner->result()->stop() would work, but this is probably a "dirty" solution. A neater way might be to register a Test::Unit::Listener (I haven't tried) and use the add_failure event to fish the Result object out from the failure exception? Remember, there's more than one way to do it! Matthew #8-) |