Docker-compose JUnit5 extension

Run docker-compose in JUnit5 tests

License

License

Apache-2.0
Categories

Categories

Docker Container Virtualization Tools JUnit Unit Testing
GroupId

GroupId

io.github.yashchenkon
ArtifactId

ArtifactId

docker-compose-junit5
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

Docker-compose JUnit5 extension
Run docker-compose in JUnit5 tests
Project URL

Project URL

https://github.io/yashchenkon/dockercomposejunit5
Source Code Management

Source Code Management

https://github.com/yashchenkon/dockercomposejunit5

Download docker-compose-junit5

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.yashchenkon/docker-compose-junit5/ -->
<dependency>
    <groupId>io.github.yashchenkon</groupId>
    <artifactId>docker-compose-junit5</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.yashchenkon/docker-compose-junit5/
implementation 'io.github.yashchenkon:docker-compose-junit5:1.0.0'
// https://jarcasting.com/artifacts/io.github.yashchenkon/docker-compose-junit5/
implementation ("io.github.yashchenkon:docker-compose-junit5:1.0.0")
'io.github.yashchenkon:docker-compose-junit5:jar:1.0.0'
<dependency org="io.github.yashchenkon" name="docker-compose-junit5" rev="1.0.0">
  <artifact name="docker-compose-junit5" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.yashchenkon', module='docker-compose-junit5', version='1.0.0')
)
libraryDependencies += "io.github.yashchenkon" % "docker-compose-junit5" % "1.0.0"
[io.github.yashchenkon/docker-compose-junit5 "1.0.0"]

Dependencies

compile (3)

Group / Artifact Type Version
com.palantir.docker.compose : docker-compose-rule-junit4 jar 0.32.1
org.junit.jupiter : junit-jupiter-engine jar 5.1.1
org.junit.jupiter : junit-jupiter-api jar 5.1.1

Project Modules

There are no modules declared in this project.

Docker-compose JUnit5

Build Status

Library allows developers to run docker-compose from Java JUnit5 tests. Inspired by docker-compose-rule

This library allows:

  • start containers defined in docker-compose.yml before JUnit5 tests and shutdown them afterwards
  • write docker-compose logs to separate folder
  • wait until services become available

Usage

Annotate your test class with @DockerCompose annotation:

@DockerCompose
public class Test1 {

    @Test
    public void shouldDoSomething() {
    }
}

By default, extension looks for docker-compose.yml in the classpath root, doesn't writes logs and doesn't wait until services are available.

To manage all this stuff, specify appropriate attributes of @DockerCompose annotation.

@DockerCompose(
        file = "docker-compose-custom.yml",
        logs = "target/logs/docker-compose",
        waitFor = {
                @WaitFor(
                        service = "service-1",
                        healthCheck = @HealthCheck(
                                type = HealthCheckType.TO_RESPOND_OVER_HTTP,
                                port = 8080,
                                timeout = 60
                        )
                ),
                @WaitFor(
                        service = "service-2",
                        healthCheck = @HealthCheck(type = HealthCheckType.ALL_PORTS_OPEN)
                )
        }
)
public class Test2 {
    
    @Test
    public void verify() {
    }
}

In this case, it'll use docker-compose-custom.yml from the classpath, write logs to target/logs/docker-compose dir and wait until service-1 and service-2 become available.

Accessing a service

This extension implements ParameterResolver interface, so you can pass DockerComposeRule object as an argument of your test:

@DockerCompose
public class DockerComposeCustomExtensionTest {

    @Test
    public void verifyParameterExtension(final DockerComposeRule dockerComposeRule) {
        
    }
}

For additional details of DockerComposeRule, please go to docker-compose-rule

Installation

Add following dependency to pom.xml:

<dependency>
    <groupId>io.github.yashchenkon</groupId>
    <artifactId>dockercomposejunit5</artifactId>
    <version>1.0.0</version>
</dependency>

Versions

Version
1.0.0