gradle-integration-test-plugin
gradle-integration-test-plugin copied to clipboard
Gradle plugin with integrationTest task
Integration Test Gradle Plugin
Single line in build.gradle.kts to enable integration tests in JVM projects
Zero configuration, single responsibility gradle plugin for integration tests.
- Adds
integrationTesttask that executes tests undersrc/integration/*. - Adds
testAlltask that executes tests undersrc/test/*andsrc/integration/*. - Handles flags parameters to skip tests
skipTest,skipIntegrationTest,skipUnitTest. - Makes integration classpath extend test classpath and main classpath (in this order).
- Makes sure IntelliJ idea treats
src/integration/*as test sources. - Exposes kotlin internal scope (from main and test module) to integration tests.
- Integrates with test coverage tools like Jacoco and Kover.
- Integrates with test frameworks like JUnit5, Spock and Kotest.
- Compatible with gradle configuration cache and lazy task configuration.
Using the plugin
Update build.gradle.kts
plugins {
id("com.coditory.integration-test") version "2.2.2"
}
dependencies {
integrationImplementation(...)
}
Add integration tests under src/integration. That's it!
There are more details below but the rest is quite obvious as it suppose to be.
Sample usages with different test frameworks
See a project with all the examples.
Java + JUnit5 (project)
// build.gradle.kts
plugins {
id("java")
id("com.coditory.integration-test") version "2.2.2"
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.11.0")
}
tasks.withType<Test> {
useJUnitPlatform()
}
Groovy + Spock (project)
// build.gradle
plugins {
id "groovy"
id "com.coditory.integration-test" version "2.2.2"
}
dependencies {
testCompile "org.spockframework:spock-core:2.4-M4-groovy-4.0"
}
tasks.withType(Test) {
useJUnitPlatform()
}
Kotlin + JUnit5 (project)
// build.gradle.kts
plugins {
kotlin("jvm") version "2.0.21"
id("com.coditory.integration-test") version "2.2.2"
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.3")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.11.3")
}
tasks.withType<Test> {
useJUnitPlatform()
}
Kotlin + Kotest (project)
// build.gradle.kts
plugins {
kotlin("jvm") version "2.0.21"
id("com.coditory.integration-test") version "2.2.2"
}
dependencies {
testImplementation("org.junit.jupiter:junit-jupiter-api:5.11.3")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.11.3")
testImplementation("io.kotest:kotest-runner-junit5:5.9.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 -PskipTest
# Skip tests from /src/test
./gradlew clean build -x test
# ...or skipUnitTests=true/false
./gradlew clean build -PskipUnitTest
# Skip tests from /src/integration
./gradlew clean build -x integrationTest
# ...or skipIntegrationTests=true/false
./gradlew clean build -PskipIntegrationTest
Test filtering is supported as well:
./gradlew iT --tests com.coditory.SampleTest.shouldWork
The no-plugin alternative
If you're against adding plugins to your build file, simply copy-paste the configuration from:
...though mind the boilerplate
Migrating from 1.x.x to 2.x.x
- Skipping flags changed names. Use
skipTests,skipUnitTests,skipIntegrationTestsinstead ofskipTest,skipUnitTest,skipIntegrationTest. - Added integration with Jacoco - coverage from integration tests is automatically included in report.
- Integration with JUnit4 is dropped.