views:

230

answers:

1

I am writing a few test cases that depend on the database being available, so on the @Before and @After I open and close the session (Hibernate), as well as start and finish the transaction.

Now in the process of development sometimes I get exceptions in the test cases, so the @After is never called and I can't clean up (or rollback the transaction which is what I'd like to do).

I've (briefly) checked the documentation and could not find how to catch these unexpected exceptions so I can rollback and let the rest of the tests work ok.

Any pointers ?

+3  A: 

According to this resource:

http://junit.org/apidocs/org/junit/After.html

The @After method is guaranteed to run, even if an exception is thrown. You're not calling that method explicitly, are you?

Outlaw Programmer
Duh .... The super class has a @After that was still trying to access the session ....
webclimber