Giter Club home page Giter Club logo

mysql-junit4's Introduction

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.0.1</version>
</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!

mysql-junit4's People

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.