Inspecting in-mem HSQLDB

Sometimes, for automatic testing of your Java application, you need to configure a DB connection. Most of the times the decision is to go for an in-memory database and HSQLDB is a prime candidate.

And some other times your tests will be failing and it would be great to see the DB status before the failure. I already knew of the option of running HSQLDB as a server, but a colleague showed me a simpler way, with less configuration.

Simply add the following lines to the beginning or the test:

System.setProperty(“java.awt.headless”, “false”); // to prevent an exception related to awt running headless
DatabaseManagerSwing.main(new String[]{“--url”, “jdbc:hsqldb:mem:testdb”, “--user”, “sa”, “--password”, “”}); //to launch a separate a simple DB-inspector window

Normally, you’re going to put a breakpoint in your test right before the failing assertions. If the DB-inspector window freezes it’s because the breakpoint is configured to stop all threads. You will need to configure your IDE to not stop the DB-inspector thread (on IntelliJ IDEA, right click on the breakpoint and you’ll get the menu that allows you to change this).

References:

One last thing: I’m new at writing posts. If you have any suggestions to make this post more clear, please write a comment.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.