April 28, 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 Java.net 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.

Posted by rob@rojotek at April 28, 2004 12:51 AM
Comments

Glad you found it useful - keeping the test runs short is important to me otherwise it'll put me off writing them! ;-) Out of interest, do you use JUnit test suites?

Posted by: Simon Brown at April 29, 2004 11:48 AM

As much of the time (excluding integration time) I run the tests using the IntelliJ test runner, I don't use test suites.

Posted by: Rob Dawson at April 29, 2004 02:07 PM