The author of Nails and Hammers shows how to use the TestSpy pattern (described in Gerard Meszaros' xUnit Test Patterns) in combination with db4o. TestSpy is a class that can be ‘injected' in a tested class in order to instrument and capture its behaviour. In this blog post TestSpy is used to persist objects that were being created in the tested method to be verified at a later stage.

"I had wide number of choices how to implement the persistence - using a file, a regular sql database, embedded database like HSQLDB or H2.  I really wanted something simple, no extra server administration, table creation or  O/R mapping definition. I wanted to store and retrieve objects, so I decided to give it a try with an embedded object-oriented database. I chose db4o for no particular reason except that it seems to be pretty well established as a product and is coming with an open source license (GPL, though)" says the author.

"Despite having not much of former exposure to db4o, it turned out pretty quick and simple. I followed the tutorial and I had the whole testing up and running in about 30 minutes".

You can read the blog post here.