7

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.

1
  • 1
    I've got the same issue but with Kotlin/Native, I've managed to see the result by opening the "output.bin" file located at "build/test-results/nativeTest/binary", but it might not be present in JVM tests. It's not the ideal solution, but at least I could see it. Hope you can too! Commented Mar 20, 2020 at 9:44

4 Answers 4

1

You can make it work by adding this to your build.gradle.kts:

tasks.withType<Test> {
    testLogging {
        showStandardStreams = true
    }
}
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

0

In my case, this worked:

afterEvaluate {
    tasks.withType<AbstractTestTask> {
        testLogging {
            showStandardStreams = true
        }
    }
}

Comments

0

To enable standard output in your Kotlin Multi Platform tests you need to enable STANDARD_OUT events in your testLogging configuration.

// kotlin dsl
tasks.withType<AbstractTestTask>().configureEach {
    testLogging {
        events = setOf(
            TestLogEvent.STANDARD_OUT,
        )
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.