https://kotlinlang.org logo
Title
d

dave08

08/22/2021, 11:18 AM
How do I run all the tests in a gradle multi-module project? So far, I need to run each module's tests seperately, I can't just run gradlew test...
t

Tobi M.

08/22/2021, 11:24 AM
You should be able to run
./gradlew :<module-name>:test
to just run the tests in one module.
d

dave08

08/22/2021, 11:25 AM
Yeah, that's what I'm currently doing, but I need to run the whole suite in the CI, or after making major changes...
s

sam

08/22/2021, 11:30 AM
just do
./gradlew check
or
/.gradlew test
at the top level
See kotest's own github actions files for an example
d

dave08

08/22/2021, 11:31 AM
Tried, didn't work...
s

sam

08/22/2021, 11:31 AM
what's the error
d

dave08

08/22/2021, 11:36 AM
Test events not received
s

sam

08/22/2021, 11:36 AM
sounds like you don't have the test task configured at your project root
you can do that by adding the kotlin or java plugin to the build.gradle.kts for the root project
d

dave08

08/22/2021, 11:38 AM
I have this at the root:
plugins {
    kotlin("jvm")
    kotlin("kapt")
    id("com.squareup.anvil")
}
And in Intellij's gradle toolbox, it exists under the root...
b

Big Chungus

08/22/2021, 11:40 AM
Drop this in your root module
allprojects {
  afterEvaluate {
    tasks {
        if (tasks.findByName("test") == null) {
          register("test") {
            dependsOn(withType(KotlinTest::class))
            group = "verification"
        }
      }
    }
  }
}
Then running
./gradlew test
will run all tests in all modules, regardless if it's a jvm or mpp module
s

sam

08/22/2021, 11:41 AM
That's only if you're using the kotest gradle plugin right ?
d

dave08

08/22/2021, 11:41 AM
kotest gradle plugin?
s

sam

08/22/2021, 11:42 AM
Oh never mind, I see, @Big Chungus means you don't need to use
check
task.
This is the snippet I use to configure tests @dave08
tasks.named<Test>("jvmTest") {
   useJUnitPlatform()
   filter {
      isFailOnNoMatchingTests = false
   }
   testLogging {
      showExceptions = true
      showStandardStreams = true
      events = setOf(
         org.gradle.api.tasks.testing.logging.TestLogEvent.FAILED,
         org.gradle.api.tasks.testing.logging.TestLogEvent.PASSED
      )
      exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
   }
}
d

dave08

08/22/2021, 11:44 AM
KotlinTest::class
or
KoTest::class
? And @sam, that does the same as what he posted?
s

sam

08/22/2021, 11:44 AM
no, we're giving different options I think
b

Big Chungus

08/22/2021, 11:45 AM
Yes, kotest != gradle
So to get
./gradlew test
to execute all your modules, use my suggestion above. I cannot comment on kotest plugin.
d

dave08

08/22/2021, 11:46 AM
build.gradle.kts:78:23: Unresolved reference: findByName ...
b

Big Chungus

08/22/2021, 11:48 AM
How's this
allprojects {
    afterEvaluate {
        tasks {
            if (findByName("test") == null) {
                register("test") {
                    dependsOn(withType(KotlinTest::class))
                    group = "verification"
                }
            }
        }
    }
}
d

dave08

08/22/2021, 11:53 AM
@sam I copied this from hoplite:
tasks.named<Test>("test") {
    useJUnitPlatform()
    testLogging {
        showExceptions = true
        showStandardStreams = true
        exceptionFormat = FULL
    }
}
and some tests started running, there's a few compile errors now, but it seems like it's running. Thanks to both of you for pointing out the right direction!
s

sam

08/22/2021, 11:53 AM
you were probably missing the useJUnitPlatform() at the top level then
👍🏼 1
d

dave08

10/24/2021, 3:28 PM
A while passed since I tried this... I'm still having these problems. Only my domain module's tests are being run... I really wonder what could be wrong...?