|
From: David H. <wa...@us...> - 2004-11-05 00:43:38
|
On Thu, Nov 04, 2004 at 09:55:46AM -0800, Luke Bayes wrote: > > I guess it might still be possible to optionally implement this > > mechanism based on the presense of the Error class, or something. > > Does ASUnit already have a mechanism for dealing with exceptions (per > > the runProtected() method of junit.framework.TestResult)? > > Actually no - but I would like to hear more about this. Basically, there is some code in there to catch Java exceptions and errors. These can occur for a couple of reasons: - Something went wrong during the test, raising a Throwable - One of the asserts failed, raising an AssertationFailedError If the former happens, the TestResult records an 'error' for this test. If the latter happens, the TestResult records a 'failure' for this test. You can see this portion of the JUnit source code here: http://cvs.sourceforge.net/viewcvs.py/junit/junit/junit/framework/TestResult.java?rev=1.5&view=auto > > Oh, just to clarify: I'm not suggesting that all tests halt on the first > > error, just that a given testFoo() method will exit on the first > > assertion that fails. > > Hmm. I might need to know more about this feature. I'm not exactly > sure what we'd be looking for there. It would probably be a whole lot of trouble to implement in a Flash 6 compatible way (i.e. avoiding try-catch), so I doubt that I'll bother. Anyway, here's my stab at explaining this aspect of JUnit architecture: A test should just be checking a single, small part of the system. If, during the course of the test an assertion fails, the test as a whole has failed, so there's no need to continue it. JUnit actively avoids executing code after a problem has been detected because the system being tested is now in an 'undefined' state; further use could now cause an error (i.e. the tested code could throw an exception). So, the JUnit framework needs to go though some hoops to abort the current test, and move on to the next one. If it didn't, you might end up looking to fix a problem that's actually a result of some earlier failure in your test. (All just my opinion.) ASUnit is very useful as it works currently, but this feature will help in a few tricky situations. dave |