Monthly Archives: April 2004

Tuning tests…. fun for all the family

On my last project I developed a bit of a reputation for tuning our test suite, working hard at keeping the tests running as quickly as possible…. so when I saw Simon’s recent blog on about Global setUp and tearDown for test cases I made a mental note, tucking the thought away for definite later use.

Today I just put the approach into practice in a project I am building. The system has an embedded HSQLDB database. I have about 30 tests that rely on the database being there. The remainder of my suite of 130 tests don’t hit the database.

I have in the past been using a setUp and tearDown to ensure the database is running for the tests that need it, shutting it down at the end of each test. With the use of the shutdown hook I could ensure that the database gets closed at the end of my tests, starting it in the static initialiser, in the end cutting the runtime from about 20 seconds to under 10… It might not sound like a big deal but it really does make a difference.