02 June 2019

I have just released org.firebirdsql:firebird-testcontainers-java:1.0.0, based on Testcontainers.

This library allows you to start a Firebird docker container for a JUnit 4 or 5 test or manually from your code. This can be useful for JUnit-based integration tests.

For a very simple example, add to your pom.xml:

<dependency>
    <groupId>org.firebirdsql</groupId>
    <artifactId>firebird-testcontainers-java</artifactId>
    <version>1.0.0</version>
    <scope>test</scope>
</dependency>
<dependency>
    <groupId>org.firebirdsql.jdbc</groupId>
    <artifactId>jaybird-jdk18</artifactId>
    <version>3.0.6</version>
    <scope>test</scope>
</dependency>

And create a test:

/**
  * Simple test demonstrating use of {@code @Rule}.
  */
public class ContainerExampleTest {

     @Rule
     public final FirebirdContainer container = new FirebirdContainer();

     @Test
     public void canConnectToContainer() throws Exception {
         try (Connection connection = DriverManager
                 .getConnection(container.getJdbcUrl(), container.getUsername(),
                     container.getPassword());
              Statement stmt = connection.createStatement();
              ResultSet rs = stmt.executeQuery("select CURRENT_USER from RDB$DATABASE")) {
             assertTrue("has row", rs.next());
             assertEquals("user name",
                 container.getUsername().toUpperCase(), rs.getString(1));
         }
     }
}