The brand new 0.6 release of the Embedded DB JUnit Rule has been released with some notable new features:

A new initialization plugin API

You can now implement custom initialization code by implementing the new InitializationPlugin interface:

public interface InitializationPlugin {

void connectionMade(final String name, final Connection connection);
}

Liquibase support

To initiate the embedded in-memory H2 database created by the @Rule, add the plugin to the @Rule initialization using the fluent Builder API:

@Rule
public EmbeddedDatabaseRule embeddedDatabaseRule = EmbeddedDatabaseRule
.builder()
.withMode(EmbeddedDatabaseRule.CompatibilityMode.MSSQLServer)
.initializedByPlugin(LiquibaseInitializer.builder()
.withChangelogResource("example-changelog.sql")
.build())
.build();

You can then get a DataSource or Connection from the JUnit rule to be used in your test

@Test
public void testCanConnect() throws Exception {

try(final Connection connection = embeddedDatabaseRule.getConnection()) {
// test code

}

}