I try to split the tests into unit tests and integ...
# community-support
h
I try to split the tests into unit tests and integration tests in my project(Kotlin, and Gradle Kotlin DSL), I added the following to ``build.gradle.kts`
Copy code
val integrationTest = task<Test>("integrationTest") {
    description = "Runs integration tests."
    group = "verification"

//    testClassesDirs = sourceSets["intTest"].output.classesDirs
//    classpath = sourceSets["intTest"].runtimeClasspath
//    shouldRunAfter("test")

    useJUnitPlatform{
        filter {
            include("**/*IT.class")
        }
    }
}

tasks.check{
    dependsOn(integrationTest)
}
I have modified the integration test classes with a
IT
postfix. I have used
includes(**/*IT.class)
or
includeTestsMatching("*IT")
, it does not work when run
./gradlew clean intergrationTest
. All tests are run as before. Any suggestion here?
v
Nesting
filter
in
useJUnitPlatform
does not make much sense, that is just visual clutter as
filter
is a method on the
Test
task directly. Nesting
include
in
filter
does not make much sense, that is just visual clutter as
include
is a method on the
Test
task directly. So what you shows is the same as
Copy code
useJUnitPlatform()
include("**/*IT.class")
Both the options you showed should imho work though. Can you maybe knit an MCVE that demoes the problem? Btw. you should not use
task("...")
as that is an eager api and not leveraging task-configuration avoidance. You can easily see this from the return type being the concrete task and not some provider.
h
@Vampire Thanks, use
tasks.register
instead. But the filter in integrationTest still does not work as expected, it still includes all tests in the
integrationTest
task, although I have moved the filter out of
useJunitPlatform
.
I know the reason now, the custom integration test task filter config inherits from the default
test
task. I have to exclude the tests defined in the test filter.