Giter Club home page Giter Club logo

assortmentofjunitrules's Introduction

AssortmentOfJUnitRules

Build Status Maven Central

This is a small selection of useful (for me) rules for building integration tests with AWS, Hadoop, Spark and Mongo. These rules can be used together to start up a mini environment required for a test.

The package has only one hard dependency - JUnit. All sub-rules will expect their requirements to be provided.

Each rule has a JUnit test which also serves as an example.

How to use

Utilizing your dependency framework of choice (Maven shown below) include both it and the rules dependencies in your applications build system.

<dependency>
  <groupId>com.github.mlk</groupId>
  <artifactId>assortmentofjunitrules</artifactId>
  <version>1.5.**</version>
</dependency>

Check above for the most recent release.

SparkRule

Starts up and shuts down a local Spark context between JUnit tests. Required spark-core.

Maven example:

        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.11</artifactId>
            <version>1.4.1</version>
        </dependency>

Example

HadoopDFSRule

Starts up and shuts down a local Hadoop DFS cluster between JUnit tests. Requires hadoop-minicluster.

Maven example:

        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-client</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-minicluster</artifactId>
            <version>2.8.0</version>
        </dependency>

Example

HadoopYarnRule

Starts up and shuts down a local Hadoop DFS and YARN cluster between JUnit tests. Requires hadoop-minicluster.

Example

MongoRule

Uses Flapdoodles' Embed Mongo to start up a Mongo server before each test and shut it down after each test. Requires de.flapdoodle.embed.mongo

Maven Example:

        <dependency>
            <groupId>de.flapdoodle.embed</groupId>
            <artifactId>de.flapdoodle.embed.mongo</artifactId>
            <version>2.0.0</version>
        </dependency>

Example

SftpRule

Uses Apache Mina SSHd to start up a SFTP server before each test and shut it down after each test. Requires org.apache.sshd.sshd-core

Maven Example:

        <dependency>
            <groupId>org.apache.sshd</groupId>
            <artifactId>sshd-core</artifactId>
            <version>1.4.0</version>
        </dependency>

Example

S3MockRule

Use S3Mock to create a S3 mock server at before each test and shut it down after each test. Requires io.findify.s3mock_2.11

Maven Example:

      <dependency>
          <groupId>io.findify</groupId>
          <artifactId>s3mock_2.11</artifactId>
          <version>0.2.0</version>
      </dependency>

Example

LocalDynamoDbRule

Uses the Local Amazon DynamoDB to create a in-memory, local DynamoDB instance. This rule handles all the SQLite native libraries stuff for you.

Maven Example:

<!--Dependency:-->
<dependencies>
    <dependency>
       <groupId>com.amazonaws</groupId>
       <artifactId>DynamoDBLocal</artifactId>
       <version>[1.11,2.0)</version>
    </dependency>
</dependencies>
<!--Custom repository:-->
<repositories>
    <repository>
       <id>dynamodb-local-oregon</id>
       <name>DynamoDB Local Release Repository</name>
       <url>https://s3-us-west-2.amazonaws.com/dynamodb-local/release</url>
    </repository>
</repositories>

Example

HttpDynamoDbRule

Uses the Local Amazon DynamoDB to create a in-memory, local DynamoDB instance running over HTTP. This rule handles all the SQLite native libraries stuff for you.

Maven Example:

<!--Dependency:-->
<dependencies>
    <dependency>
       <groupId>com.amazonaws</groupId>
       <artifactId>DynamoDBLocal</artifactId>
       <version>[1.11,2.0)</version>
    </dependency>
</dependencies>
<!--Custom repository:-->
<repositories>
    <repository>
       <id>dynamodb-local-oregon</id>
       <name>DynamoDB Local Release Repository</name>
       <url>https://s3-us-west-2.amazonaws.com/dynamodb-local/release</url>
    </repository>
</repositories>

Example Example of it in use

PostgresRule

Uses Embedded PostgreSQL Server to start up a Postgres server during each test.

Maven Example:

      <dependency>
          <groupId>ru.yandex.qatools.embed</groupId>
          <artifactId>postgresql-embedded</artifactId>
          <version>2.2</version>
      </dependency>

Example

ElasticSearchRule

Uses Embedded ElasticSearch to start up a ElasticSearch server during each test.

Maven Example:

    <dependency>
        <groupId>pl.allegro.tech</groupId>
        <artifactId>embedded-elasticsearch</artifactId>
        <version>2.7.0</version>
        <scope>test</scope>
    </dependency>

Example

Helper Rules

SpringDatabaseRule

Sets up all the Spring Boot stuff when using Spring Boot and a supported database. This must be a @ClassRule.

SpringElasticSearchRule

Sets up all the Spring Boot stuff when using Spring Boot and a Elastic Search. This must be a @ClassRule.

NativeLibraryRule

Finds native libraries in your classpath and moves them to a single folder. See the DynamoDB rules for an example.

assortmentofjunitrules's People

Contributors

mlk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

assortmentofjunitrules's Issues

Support Junit 5

Wondering if you'd consider adding support for Junit 5. It no longer has Rules, but I believe the same can be accomplished with the new Extension support.

DynamoDBRule and Spring Boot

Hi I have successfully used your LocalDynamoDbRule in a sort of functional test, but I would also like to use DynamoDb against my Repository instances (spring data), but currently, I can't because Spring Boot rather helpfully inserts it Hikari Driver in place. I'm assuming that I would need a way to create a SpringDatabaseRule, but can't because neither LocalDynamoDbRule or DynamoDbRule implement DatabaseRule. I'm looking into making another rule that covers this, but I think it would be handy, if your library included this.

Nice job, by the way.

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.