application-test.properties

It is common to want to run all tests against an in-memory H2 database. A simple way to do this is to add src/test/resources/application-test.properties (or application-test.yaml) and point the datasource at H2.

Run all tests against H2 in-memory.

For new applications, prefer explicit test wiring using Database.builder() and loadFromProperties() rather than relying on implicit bootstrap.

Example application-test.properties

## Create DB from scratch prior to running tests
ebean.db.ddl.generate=true
ebean.db.ddl.run=true

## Use H2 when running tests
datasource.db.username=sa
datasource.db.password=
datasource.db.databaseUrl=jdbc:h2:mem:tests
datasource.db.databaseDriver=org.h2.Driver

Programmatic builder

Keep test startup explicit and load the test configuration via the builder:

@Override
public Database getObject() {

  return Database.builder()
    .name("db")
    .loadFromProperties()
    .defaultDatabase(true)
    .build();
}

For broader integration testing support, including Docker-backed databases, see docs / testing.