2

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?

mixel
  • 25,177
  • 13
  • 126
  • 165
  • 1
    Does this answer your question? [Gradle: How to Display Test Results in the Console in Real Time?](https://stackoverflow.com/questions/3963708/gradle-how-to-display-test-results-in-the-console-in-real-time) – Animesh Sahu May 06 '20 at 15:22
  • @AnimeshSahu Yes, thanks! But is there a way to avoid other extra output? May be by configuring test task? – mixel May 06 '20 at 15:26
  • Which type of extra output? – Animesh Sahu May 06 '20 at 15:28
  • Does this one help? https://stackoverflow.com/questions/34766301/suppressing-interactive-output-in-gradle-exec-tasks – Animesh Sahu May 06 '20 at 15:31
  • Providing `-i` option to `./gradlew check -i` gives me a ton of other output with INFO logging level which makes reading it more difficult. – mixel May 06 '20 at 15:32
  • That solution isn't suitable for my case (or I don't know how to apply it). – mixel May 06 '20 at 15:34

1 Answers1

1

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>
      }
    }
  }
}  
mixel
  • 25,177
  • 13
  • 126
  • 165