Is it possible to run tests only on Common modules...
# gradle
n
Is it possible to run tests only on Common modules via Gradle?
There appears to be only three test related tasks listed via `gradlew tasks`:
Copy code
allTests - Runs the tests for all targets and create aggregated report
check - Runs all checks.
linuxX64Test - Executes Kotlin/Native unit tests for target linuxX64.
o
how can you run a common test by itself? doesn't it have no execution engine by definition?
n
I have implemented the tests for the linuxX64 module, and tried to run the tests however the
kotlin.NotImplementedError
error keeps on occurring:
Copy code
> Task :linuxX64Test FAILED

org.digieng.kmetrics.core.GaugeMetricTest.create text with name and value FAILED
    kotlin.NotImplementedError

1 test completed, 1 failed
s
There seems to be reporting stuff just not fully documetned / fleshed out. Doing a multi platform lib, this is what I used. the
linux
portion isn't generating tests. But it has an option. Additionally I found I couldn't call
allTests
, I need to call
jvmTest
,
jsTests
, etc. I think we would need to loop on the allTests task for configuration
Copy code
tasks {
    val jvmTest by getting(org.jetbrains.kotlin.gradle.targets.jvm.tasks.KotlinJvmTest::class) {
        this.useJUnit()
        this.reports.junitXml.isEnabled = true
    }
    val linuxX64Test by getting(org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest::class) {
        reports.junitXml.apply {
            isEnabled = true
        }
    }
}
n
That does look a bit strange that the allTests task doesn't exist. With Kotlin MPP the allTests task should automatically exist when the Kotlin multiplatform plugin is applied.
s
allTests
still exists. It just won't have the reporting elements present. This explicitly sets reporting on tasks, there's a similar syntax for
js
. So if you run
allTests
it doesn't provide xml reporting, just the
html
reports. I would think it's something like
Copy code
for task in allTests
if task.name == jvmTests -> junitXML = true
if task.name == jsTests -> cobertura = true
if task.name == linuxX64Test -> junitXML = true
But I couldn't determine how to loop
allTests
.
n
Sounds like you have encountered a limitation where only HTML tests reports are available in a Kotlin Multiplatform project.
s
Yep you then need to dive down and configure each respective targets reporting/coverage