Skip to content

A JUnit rule that manages a Docker container lifecycle around test statements.

License

Notifications You must be signed in to change notification settings

itzg/junit-rule-docker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CircleCI Download

Provides a JUnit rule that starts a container prior to test execution, enables access to the exposed ports of the container, and removes the container after test execution.

This artifact is available at JCenter, so it may be included by adding this dependency:

<dependency>
    <groupId>me.itzg.testing</groupId>
    <artifactId>junit-rule-docker</artifactId>
    <version>1.3</version>
    <scope>test</scope>
</dependency>

and the jcenter repository, if you haven't already:

<repository>
    <snapshots>
        <enabled>false</enabled>
    </snapshots>
    <id>bintrary</id>
    <name>bintray</name>
    <url>http://jcenter.bintray.com</url>
</repository>

The following example shows how to use the rule to start an Elasticsearch instance, waiting for Elasticsearch to start, and lookup access to the container's port 9200:

@Rule
public DockerRule dockerRule = new DockerRule("itzg/elasticsearch:5")
                                   .waitForLog("started");

@Test
public void testAccess() throws Exception {

    InetSocketAddress accessToPort = dockerRule.getAccessToPort(9200);
    
    ...

About

A JUnit rule that manages a Docker container lifecycle around test statements.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages