'Observe stdout from multiplatform kotlin commonTest code
I just want to see the output from a few simple println(...)
in my Kotlin mulitplatform commonTest
code. My build.gradle.kts
looks a little like:
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTarget
plugins {
kotlin("multiplatform") version "1.3.61"
kotlin("plugin.serialization") version "1.3.61"
}
kotlin {
sourceSets {
val commonMain by getting { ... }
val commonTest by getting {
dependencies {
implementation("org.jetbrains.kotlin:kotlin-test-common")
implementation("org.jetbrains.kotlin:kotlin-test-annotations-common")
}
}
val jvmMain by getting { ... }
val jvmTest by getting {
dependencies {
implementation(kotlin("test-junit"))
}
}
// and so on ...
}
}
Meanwhile in ~/src/commonTest/kotlin/my/company/library/CommonTest.kt
:
package my.company.library
import kotlin.test.*
class CommonTest() {
@Test
fun testTrue() {
println("Hello, test!")
assertTrue(true)
}
}
For the time being I'm running tests like this
./gradlew jvmTest
I want to see Hello, test!
show up in the terminal. I don't mind typing a little extra on the command line.
Various answers around SO involving testLogging.showStandardStreams
refer to the "standard" gradle test target, and I'm not sure how or if it actually interacts with the multiplatform test targets.
Solution 1:[1]
You can make it work by adding this to your build.gradle.kts
:
tasks.withType<Test> {
testLogging {
showStandardStreams = true
}
}
Solution 2:[2]
Add the following to your gradle config:
iosTest {
testLogging {
events("PASSED", "FAILED", "SKIPPED")
exceptionFormat = "full"
showStandardStreams = true
showStackTraces = true
}
}
for JVM it would be similar but then under the block jvmTest
.
Solution 3:[3]
In my case, this worked:
afterEvaluate {
tasks.withType<AbstractTestTask> {
testLogging {
showStandardStreams = true
}
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Wilko |
Solution 2 | Werner Altewischer |
Solution 3 | BoD |