db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel John Debrunner <...@apache.org>
Subject Should JUnit tests automate closing statements
Date Fri, 29 Jun 2007 03:43:38 GMT
I see a lot of test fixtures that do not close the 
Statement/PreparedStatement/CallableStatement objects they open. It's 
easy to forget to add the close, especially when the fixture gets long 
and multiple statement objects are used.

I thinking about automating the close on tearDown() in BaseJDBCTestCase 
for any statement opened via any utility method, such as 
createStatement(), prepareStatement(), prepareCall() etc.

This would require keeping a list of statement objects in 
BaseJDBCTestCase that was processed on tearDown. Ideally this list would 
never get too big as fixtures are meant to be small. Maybe for utility 
methods that create statements (such as assetCompileError) there could 
be a utility method to close a statement that also removed it from the 
tracking list?

Then a test writer would not have to close any jdbc statement (or 
ResultSet) but there would be no harm in doing so.

Thoughts?
Dan.

Mime
View raw message