gradle-oci-junit-jupiter

Integration of gradle-oci and junit-jupiter

APACHE-2.0 License

Stars
2

Integration of gradle-oci and junit-jupiter

How to Use

Use the Gradle OCI Plugin and add the dependency on gradle-oci-junit-jupiter in your build.gradle(.kts):

plugins {
    java
    id("io.github.sgtsilvio.gradle.oci") version "0.16.0"
}

repositories {
    mavenCentral()
}

oci {
    registries {
        dockerHub {
            optionalCredentials()
        }
    }
}

testing {
    suites {
        "test"(JvmTestSuite::class) {
            useJUnitJupiter()
            dependencies {
                implementation("io.github.sgtsilvio:gradle-oci-junit-jupiter:0.6.0")
            }
            oci.of(this) {
                imageDependencies {
                    runtime("your:image:123")
                }
            }
        }
    }
}

Configure Docker on MacOS / Windows

On MacOS and Windows host.docker.internal needs to be configured as an insecure registry in the Docker daemon configuration. Usually, host.docker.internal resolves to the address 192.168.65.254.

{
  "insecure-registries": [
    "192.168.65.254/32"
  ]
}

Your Docker subnet may be configured differently. You can determine the IP address by resolving the domain name host.docker.internal inside a container using this command:

docker run --rm busybox nslookup host.docker.internal

Start a TestContainer in Your JUnit Test

Example in Java:

class ContainerTest {
    @Test
    void start() {
        try (final GenericContainer<?> container = new GenericContainer<>(OciImages.getImageName("your/image:123"))) {
            container.start();
            //...
        }
    }
}