【问题标题】:Kotlin/Multiplatform how to see stdout/stderr of tests on console?Kotlin/Multiplatform 如何在控制台上查看测试的标准输出/标准错误?
【发布时间】:2021-01-05 05:18:12
【问题描述】:

我尝试为所有Test 类型的任务设置如下:

tasks.withType<Test> {
    testLogging {
        exceptionFormat = TestExceptionFormat.FULL
        showStandardStreams = true
        showStackTraces = true
    }
}

但该设置仅适用于JVM,而不适用于Kolin/Multiplatform上的所有目标。

如何引导/启用标准输出和标准错误流在控制台中输出?

在控制台中只打印异常名称(甚至不打印异常消息):

> Task :keyboard:linuxX64Test FAILED

com.github.animeshz.keyboard.NativeKeyboardHandlerTest.Caps lock key should be toggled when KeyDown event is triggered FAILED
    kotlin.IllegalStateException

com.github.animeshz.keyboard.NativeKeyboardHandlerTest.Test send and receive event FAILED
    kotlin.IllegalStateException

我现在不知道如何调试这个,当我在多个目标(在虚拟机上)上测试库时,我没有(想要安装)Intellij。

【问题讨论】:

    标签: kotlin gradle gradle-kotlin-dsl kotlin-multiplatform


    【解决方案1】:

    您需要为每个测试任务类型定义 testLogging,因为您目前只为 JVM 定义它,类似的东西应该在您的 build.gradle.kts 中起作用:

    tasks {
    
    
            val jvmTest by getting(Test::class) {
                testLogging {
                    events("PASSED", "FAILED", "SKIPPED")
                    exceptionFormat = TestExceptionFormat.FULL
                    showStandardStreams = true
                    showStackTraces = true
                }
            }
    
            val linuxTest by getting(KotlinNativeTest::class) {
    
                testLogging {
                    events("PASSED", "FAILED", "SKIPPED")
                    exceptionFormat = TestExceptionFormat.FULL
                    showStandardStreams = true
                    showStackTraces = true
                }
            }
    
            val jsNodeTest by getting(KotlinJsTest::class) {
                testLogging {
                    events("PASSED", "FAILED", "SKIPPED")
                    exceptionFormat = TestExceptionFormat.FULL
                    showStandardStreams = true
                    showStackTraces = true
                }
            }
    
    
        
    
    }
    

    【讨论】:

    • 感谢您为我指出正确的方向,我通过tasks.withType&lt;AbstractTestTask&gt; {...} 为所有这些人做了一次。
    猜你喜欢
    • 1970-01-01
    • 2012-07-15
    • 2019-09-03
    • 1970-01-01
    • 2010-09-21
    • 2016-08-07
    • 2013-05-11
    • 1970-01-01
    • 2014-07-19
    相关资源
    最近更新 更多