【问题标题】:How to print Kotlin tests output to console instead of html report? [duplicate]如何将 Kotlin 测试输出打印到控制台而不是 html 报告? [复制]
【发布时间】:2020-08-21 15:13:28
【问题描述】:

我有一个使用 Gradle 配置的 Kotlin 项目。见GitHub repository

它包含一个测试用例:

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

当我使用./gradlew check 命令运行测试时,我得到以下输出(省略了非必要部分):

...
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
...

println() 调用没有输出,也没有Expected value to be true. 消息。

它们都存在于html报告中,但每次打开html报告并不方便。

如何让./gradlew check 将所有输出打印到控制台而不是 html 报告?

【问题讨论】:

标签: kotlin testing gradle


【解决方案1】:

找到答案here

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

将此 sn-p 放在顶层 build.gradle.kts 中,以启用所有测试任务的标准流输出或在配置块中使用它以进行特定编译:

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

【讨论】:

    猜你喜欢
    • 2020-05-17
    • 1970-01-01
    • 2021-06-05
    • 2019-08-31
    • 1970-01-01
    • 2016-11-26
    • 1970-01-01
    • 2012-06-01
    • 1970-01-01
    相关资源
    最近更新 更多