aspose file tools*
The moose likes Testing and the fly likes DbUnit  + memory HSQLDB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "DbUnit  + memory HSQLDB" Watch "DbUnit  + memory HSQLDB" New topic
Author

DbUnit + memory HSQLDB

manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
hi,

i want to test my data access layer (DAO). for that i want to set up state before each test with hsqldb. i am using memory hsqldb so my tests are running quickly.

For the whole test suite i only need to export my database schema (ddl) once to the database.

my first ideas:
1) doing schema export in setUp() or in constructor
-> problem: in JUnit for each test case you get a new instance of your test class, i.e. a new export is done for each test case.
2) doing schema export before running test suite
-> problem: for i am using memory database the schema is dropped straight away. test suite is working on an empty schema
3) exporting schema in static initializer
-> mabe that is sensible?

-any more ideas? maybe memory database is so quick that it does not matter if i am exporting the schema for each test case?
-further more it is not clear to me when memory hsqldb database is dropped. maybe after first opened Connection is garbage collected?

another question: DbUnit is using xml files. because i/o regarding filesin files is slowing down tests, has anybody had bad/good experience with performance of DbUnit?

thank you.


aldana software engineering blog & .more
Jeanne Boyarsky
author & internet detective
Marshal

Joined: May 26, 2003
Posts: 30762
    
156

Manuel,
I would go with option #2. As long as you have a reference (probably static) to the database, it shouldn't drop the schema.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
I don't think HSQLDB's schema is dropped at all. It's an in-memory database, which means that as long as your JVM is alive the database is alive and when your JVM dies, the database vanishes.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
yes you're right.

i constructed 2 ANT-targets. first one exports the schema and the other writes data to it.

so it seems, that ANT build script gets forked (JVM start) and HSQLDB keeps in place as long as the JVM does not terminate.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: DbUnit + memory HSQLDB