Skip to content

coditory/gradle-integration-test-plugin

Repository files navigation

Integration Test Gradle Plugin

Build Coverage Status Gradle Plugin Portal Join the chat at https://gitter.im/coditory/gradle-integration-test-plugin

Zero configuration, single responsibility gradle plugin for integration tests.

  • Adds integrationTest task that executes tests under src/integration/*.
  • Adds testAll task that executes tests under src/test/* and src/integration/*.
  • Handles runtime flags parameters to skip tests: skipTests, skipIntegrationTests, skipUnitTests.
  • Makes integration classpath extend test classpath and main classpath (in this order).
  • Configures idea plugin to treat integration source dirs as test dirs (only when idea plugin is enabled or there is .idea folder in project root directory).
  • Exposes internal scope (from main and test module) to integration tests
  • Deobfuscates build gradle from boilerplate code

Enabling the plugin

Add to your build.gradle:

plugins {
  id "com.coditory.integration-test" version "1.5.0"
}

Sample usages with different test frameworks

See a project with all the examples.

Java + JUnit4 (project)

plugins {
    id "java"
    id "com.coditory.integration-test" version "1.5.0"
}

dependencies {
    testCompile "junit:junit:4.12"
}

Java + JUnit5 (project)

plugins {
    id "java"
    id "com.coditory.integration-test" version "1.5.0"
}

dependencies {
    testImplementation "org.junit.jupiter:junit-jupiter-api:5.7.2"
    testRuntime "org.junit.jupiter:junit-jupiter-engine:5.7.2"
}

tasks.withType(Test) {
    useJUnitPlatform()
}

Groovy + Spock (project)

plugins {
    id "groovy"
    id "com.coditory.integration-test" version "1.5.0"
}

dependencies {
    testCompile "org.spockframework:spock-core:2.0-groovy-3.0"
}

tasks.withType(Test) {
    useJUnitPlatform()
}

Kotlin + JUnit5 (project)

plugins {
    kotlin("jvm") version "1.7.0"
    id("com.coditory.integration-test") version "1.5.0"
}

dependencies {
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.2")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.2")
}

tasks.withType<Test> {
    useJUnitPlatform()
}

Kotlin + Kotest (project)

plugins {
    kotlin("jvm") version "1.7.0"
    id("com.coditory.integration-test") version "1.5.0"
}

dependencies {
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.2")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.2")
    testImplementation("io.kotest:kotest-runner-junit5:5.3.2")
}

tasks.withType<Test> {
    useJUnitPlatform()
}

Usage

Running tests:

# Runs tests from /src/test
./gradlew test

# Runs tests /src/integration
./gradlew integrationTest
./gradlew iT

# Runs all tests (/src/test and /src/integration)
./gradlew testAll
./gradlew tA

Skipping tests:

# Skip all tests
./gradlew clean build -x test integrationTest
# ...or skipTests=true/false
./gradlew clean build -PskipTests

# Skip tests from /src/test
./gradlew clean build -x test
# ...or skipUnitTests=true/false
./gradlew clean build -PskipUnitTests

# Skip tests from /src/integration
./gradlew clean build -x integrationTest
# ...or skipIntegrationTests=true/false
./gradlew clean build -PskipIntegrationTests

Test filtering is supported as well:

./gradlew iT --tests com.coditory.SampleTest.shouldWork

Creating a single Jacoco report for unit and integration tests:

jacocoTestReport {
    executionData(fileTree(project.buildDir).include("jacoco/*.exec"))
    reports {
        xml.enabled = true
        html.enabled = true
    }
}

The no-plugin alternative

If you're against adding plugins to your build file, simply copy-paste the configuration from:

...though it's not a one-liner, be aware of the obfuscation