How to print Kotlin tests output to console instead of html report?

Viewed 4289

I have a Kotlin project configured with Gradle. See GitHub repository.

It contains one test case:

class MergeSortTest {
    @Test
    fun sort() {
        val sorted = arrayOf(1, 3, 2, 4).mergeSorted()
        println(sorted.joinToString(" "))
        assertTrue(sorted.contentEquals(arrayOf(1, 2, 3, 4)))
    }
}

When I run tests with ./gradlew check command I get the following output (non-essential parts are omitted):

...
MergeSortTest[jvm] > sort[jvm] FAILED
    java.lang.AssertionError at MergeSortTest.kt:10
...
* What went wrong:
Execution failed for task ':allTests'.
> There were failing tests. See the report at: file:///Users/mledin/projects/kotlin-algorithm/build/reports/tests/allTests/index.html
...

There is no output from println() call and also no Expected value to be true. message.

They both are present in html report but it's not convenient to open html report each time.

How can I make ./gradlew check print all output to console instead of html report?

1 Answers

Found the answer here:

tasks.withType<Test> {
    this.testLogging {
        this.showStandardStreams = true
    }
}

Place this snippet in build.gradle.kts on top level to enable standard streams output for all test tasks or use it in configuration block for specific compilation:

kotlin {
  jvm {
    compilations {
      val test by getting {
        <insert snippet here>
      }
    }
  }
}  
Related