mysql-junit4

Convenience library for using embedded MySQL in Junt4 tests.

License

License

Categories

Categories

MySQL Data Databases JUnit Unit Testing
GroupId

GroupId

com.groupon.mysql
ArtifactId

ArtifactId

mysql-junit4
Last Version

Last Version

0.2
Release Date

Release Date

Type

Type

jar
Description

Description

mysql-junit4
Convenience library for using embedded MySQL in Junt4 tests.
Project URL

Project URL

https://github.com/groupon/mysql-junit4/
Project Organization

Project Organization

Groupon, Inc.
Source Code Management

Source Code Management

https://github.com/groupon/mysql-junit4/tree/master

Download mysql-junit4

How to add to project

<!-- https://jarcasting.com/artifacts/com.groupon.mysql/mysql-junit4/ -->
<dependency>
    <groupId>com.groupon.mysql</groupId>
    <artifactId>mysql-junit4</artifactId>
    <version>0.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.groupon.mysql/mysql-junit4/
implementation 'com.groupon.mysql:mysql-junit4:0.2'
// https://jarcasting.com/artifacts/com.groupon.mysql/mysql-junit4/
implementation ("com.groupon.mysql:mysql-junit4:0.2")
'com.groupon.mysql:mysql-junit4:jar:0.2'
<dependency org="com.groupon.mysql" name="mysql-junit4" rev="0.2">
  <artifact name="mysql-junit4" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.groupon.mysql', module='mysql-junit4', version='0.2')
)
libraryDependencies += "com.groupon.mysql" % "mysql-junit4" % "0.2"
[com.groupon.mysql/mysql-junit4 "0.2"]

Dependencies

compile (2)

Group / Artifact Type Version
com.groupon.mysql : mysql-embed jar 0.2
junit : junit jar 4.11

provided (2)

Group / Artifact Type Version
org.jdbi : jdbi jar 2.51
com.googlecode.flyway : flyway-core jar 2.2.1

test (1)

Group / Artifact Type Version
org.assertj : assertj-core jar 1.4.0

Project Modules

There are no modules declared in this project.

JUnit 4 support for Tests against MySQL

This library provides support classes for writing JUnit test against an embedded MySQL instance. The conventional way to use it makes use of JUnit 4 Rules. It basically creates an instance of MySQL, on demand, for testing purposes. It then creates connections to the MySQL database using the standard library (driver) for doing so.

It has additional explicit (optional) support for jdbi and flyway based fixtures.

    /**
     * A ClassRule will be executed before any tests in the class are run,
     * and after all of them are finished.
     */
    @ClassRule public static MySQLRule mysql = MySQLRule.global();

    /**
     * setup() will be run before each test method, and tearDown after
     * each test method.
     */
    @Rule public MySQLRule.Fixtures fixtures = mysql.createFixtures(new JDBIFixture()
    {
        @Override
        protected void before(final Handle handle)
        {
            handle.execute("create table something ( id int primary key, name varchar(255) )");
            PreparedBatch batch = handle.prepareBatch("insert into something (id, name) values (:id, :name)");
            batch.bind("id", 1).bind("name", "Gene").add();
            batch.bind("id", 2).bind("name", "Brian").add();
            batch.execute();
        }

        @Override
        protected void after(final Handle handle)
        {
            handle.execute("drop table something");
        }
    });

This library uses Connector/MXJ to embed MySQL.

Examples

Take a look at MySQLRuleExample and FlywayFixtureExample for sample code using this library.

Getting It

The easiest way is via Maven:

<dependency>
  <groupId>com.groupon.mysql</groupId>
  <artifactId>mysql-junit4</artifactId>
  <version>0.2</version>
  <scope>test</scope>
</dependency>

Licensing

This library is licensed under the 3-Clause BSD License. Note that it relies on MySQL which is GPL, but if you want to test against MySQL you should already know that!

com.groupon.mysql

Groupon

Versions

Version
0.2
0.0.1