I would like to add an additional "source set" to a Kotlin project that will contain integration tests. I have seen a few posts that talk about doing it for either a vanilla Java project or for Kotlin but using Groovy rather than the Kotlin Gradle DSL.
In summary, using the Kotlin Gradle DSL:
I would expect the directory structure to look something like:
src
main
java
kotlin
resources
test
java
kotlin
resources
integration
java
kotlin
resources
Related:
https://ryanharrison.co.uk/2018/07/25/kotlin-add-integration-test-module.html
https://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-integration-testing/
How do I add a new sourceset to Gradle?
Thanks
First, create source set and configuration:
sourceSets {
create("intTest") {
compileClasspath += sourceSets.main.get().output
runtimeClasspath += sourceSets.main.get().output
}
}
val intTestImplementation: Configuration by configurations.getting {
extendsFrom(configurations.implementation.get())
}
val intTestRuntimeOnly: Configuration by configurations.getting {
extendsFrom(configurations.runtimeOnly.get())
}
And then, create the task to run them:
val integrationTest = task<Test>("integrationTest") {
description = "Runs integration tests"
group = "verification"
testClassesDirs = sourceSets["intTest"].output.classesDirs
classpath = sourceSets["intTest"].runtimeClasspath
shouldRunAfter("test")
}
Also, you can add dependencies to be used by the new source set. For instance:
intTestImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
intTestRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:$junitVersion")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With