|
From: Roy S. <ro...@s7...> - 2010-11-02 12:18:02
|
On Nov 2, 2010, at 12:55 AM, Noel Darlow wrote: > Hi > >> I'm used to test cases where the test case stops executing as soon as >> the first assertion in it fails. Typically this is implemented by >> having the assertions throw AssertionFailure or something like that. > > There are a range of possibile behaviours if exceptions are used. I'm > not sure if they are all good. > > (1) A fail will halt execution of the current test method but other test > methods will proceed as normal. That sounds OK. Yup, this is what I would expect. > Finally, in any option, will tear down code always be run after a > throw? Left-over bits of fixture can sometimes just be a minor > nuisance but sometimes they can be more serious, if they might > contaminate future tests and cause misleading results. I would expect tearDown() to run after every test method, whether it passed or failed. A test case throwing AssertionFailure is simply a failure, so yes, tearDown() should run. The issue gets a little trickier if a test method throws something other than AssertionFailure, but only marginally. And, yes, tearDown() should run then too. The issue of cross-method contamination is why many of these X-Unit packages destroy the TestCase instance and create a new one before each test method. It's a little less efficient, but eliminates most worries of contamination. That usually leaves tearDown() nothing to do except for cleaning up external resources. -- Roy Smith roy...@s7... |