Skip to content

sokada1221/gradle-integration-test-plugin

 
 

Repository files navigation

Integration Test Gradle Plugin

Build Status 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).

Enabling the plugin

Add to your build.gradle:

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

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.2.3"
}

dependencies {
    testCompile "junit:junit:4.12"
}

Java + JUnit5 (project)

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

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

tasks.withType(Test) {
    useJUnitPlatform()
}

Groovy + Spock (project)

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

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

tasks.withType(Test) {
    useJUnitPlatform()
}

Kotlin + JUnit5 (project)

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

dependencies {
    implementation(kotlin("stdlib-jdk8"))
    implementation(kotlin("reflect"))
    testImplementation("org.junit.jupiter:junit-jupiter-api:5.6.1")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.1")
}

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
    }
}

About

Gradle plugin with integrationTest task

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Kotlin 100.0%