Hibernate utility class for dropwizard applications
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.



CircleCI Coverage Status Codacy Badge Download Javadoc License


Hibernate utility class for writing integration tests for AbstractDAO classes in dropwizard applications. It uses an in-memory database (HSQLDB) and uses hibernate functionality to auto-create the tables on startup.

This library follows what is described in this blog post: http://www.petrikainulainen.net/programming/testing/writing-tests-for-data-access-code-unit-tests-are-waste/ Bugs often slips through the unit tests with mocks. Using an in-memory database allows you to actually run the SQL scripts and remove the effort of writing mocks.

Supported versions:

Dropwizard Hibernate test util
0.9.3 0.0.1
0.9.3 0.0.2
1.3.8 1.3.8


The library is available at the maven central, so just add the dependency to pom.xml with scope set to test:



The class HibernateDAOTestUtil provides a jUnit Rule, so it can be simply used like this:

public class TestEntityDAOTest {
    public HibernateDAOTestUtil testUtil = new HibernateDAOTestUtil(TestEntity.class);
    private TestEntityDAO dao;

    public void setup() {
        this.dao = new TestEntityDAO(this.testUtil.getSessionFactory());

    public void testSaveAndQuery() {
        // We have a session opened and ready to be used.
        final Session session = this.testUtil.getSession();
        final TestEntity entity = TestEntity.builder().body("testing writing").build();

        final Optional<TestEntity> foundEntityOptional = this.dao.findById(entity.getId());

The schema is completely dropped after each test, guaranteeing test isolation. So no need to clean up after yourself, just let the database be destroyed after the test.