Monday, January 19, 2009

Using the right DB increased test coverage 10 times !!!

I have not worked on any web application which doesn' t connect to database. If we intend to write our application thru our tests or even vice versa, it becomes quite necessary that the DB we are using gives a great deal of support to the fact.
What support?
- Quickness
- ease of rebuilding
- smooth to handle with a programming language

I worked on an application recently which had no unit tests. When I joined the team I spoke to the team about benefits of tests - both unit and acceptance. The project had good amount automated acceptance tests though.

We tried the idea of in-memory DB - HSQLDB. This is a light weight database made in Java language. Using ANT (with hibernate) we created tasks like -
- generateSchema
- createDatabase
- populateDatabase
- deleteDatabase
Using these tasks we had great control over the DB. Moreover the DB being light and in-memory made writing tests very quick. We even configured it in Cruise Control.
Initially before we started with HSQLDB 10 days back, our test coverage was 3% and now it is 30%, growing exponentially.