Skip to content
Embedded MySQL server for use in tests
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src
.gitignore
.travis.yml
LICENSE
README.md
pom.xml
repack-mysql.sh

README.md

Testing MySQL Server

Maven Central Build Status

Embedded MySQL server for use in tests. It allows testing your Java or other JVM based application against a real MySQL server with no external dependencies to deploy or manage.

Usage

Add the library as a test dependency:

<dependency>
    <groupId>io.airlift</groupId>
    <artifactId>testing-mysql-server</artifactId>
    <version>8.0.12-2</version>
    <scope>test</scope>
</dependency>

Use it in your tests:

@Test
public void testDatabase()
        throws Exception
{
    try (TestingMySqlServer server = new TestingMySqlServer("testuser", "testpass", "testdb");
            Connection connection = DriverManager.getConnection(server.getJdbcUrl("testdb"));
            Statement statement = connection.createStatement()) {
        statement.execute("CREATE TABLE test_table (id bigint PRIMARY KEY)");
        statement.execute("INSERT INTO test_table (id) VALUES (123)");
    }
}

The server takes a few seconds to startup, so you will likely want to leave it running between tests. Make sure the server is always shutdown (by calling the close() method or using try-with-resources), otherwise the mysqld process will stay running after the JVM exits.

License

The code in this project is licensed under the Apache License, Version 2.0. The bundled MySQL server is licensed under the GNU General Public License (GPL), Version 2.0.

You can’t perform that action at this time.