Sometimes, for automatic testing of your Java application, you need to configure a DB connection. Most of the time the decision is to go for an in-memory database and HSQLDB is a prime candidate.
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:
Top comments (0)