How do I run all the tests in a gradle multi-modul...
# kotest
d
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
You should be able to run
./gradlew :<module-name>:test
to just run the tests in one module.
d
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
just do
./gradlew check
or
/.gradlew test
at the top level
See kotest's own github actions files for an example
d
Tried, didn't work...
s
what's the error
d
Test events not received
s
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
I have this at the root:
Copy code
plugins {
    kotlin("jvm")
    kotlin("kapt")
    id("com.squareup.anvil")
}
And in Intellij's gradle toolbox, it exists under the root...
b
Drop this in your root module
Copy code
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
That's only if you're using the kotest gradle plugin right ?
d
kotest gradle plugin?
s
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
Copy code
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
Copy code
KotlinTest::class
or
Copy code
KoTest::class
? And @sam, that does the same as what he posted?
s
no, we're giving different options I think
b
Yes, kotest != gradle
So to get
./gradlew test
to execute all your modules, use my suggestion above. I cannot comment on kotest plugin.
d
build.gradle.kts7823: Unresolved reference: findByName ...
b
How's this
Copy code
allprojects {
    afterEvaluate {
        tasks {
            if (findByName("test") == null) {
                register("test") {
                    dependsOn(withType(KotlinTest::class))
                    group = "verification"
                }
            }
        }
    }
}
d
@sam I copied this from hoplite:
Copy code
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
you were probably missing the useJUnitPlatform() at the top level then
­čĹŹ­čĆ╝ 1
d
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...?
1857 Views