• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DbUnit + memory HSQLDB

 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34860
369
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
manuel aldana
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic