如何将 testOptions.unitTests.all 转换为 gradle Kotlin dsl

问题描述 投票:0回答:2

如何在 Gradle 中将这段代码从 Groovy 翻译为 Kotlin DSL?

testOptions.unitTests.all {
    testLogging {
        exceptionFormat = "full"
        events "passed", "failed", "standardError"
        showCauses true
        showExceptions true
    }
}
gradle android-gradle-plugin gradle-kotlin-dsl
2个回答
5
投票

使用这个:

import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent

testOptions.unitTests.apply {
    all(KotlinClosure1<Test, Test>({
        apply {
            testLogging.exceptionFormat = TestExceptionFormat.FULL
            testLogging.events = setOf(
                TestLogEvent.PASSED,
                TestLogEvent.FAILED,
                TestLogEvent.STANDARD_ERROR
            )
            testLogging.showCauses = true
            testLogging.showExceptions = true
        }
    }, this))
}

0
投票

这是已接受答案的更清晰版本:

testOptions {
    unitTests {
        isReturnDefaultValues = true
        isIncludeAndroidResources = true
      
        all {
            it.apply {
            testLogging {
                events("started", "passed", "skipped", "failed")
            }
        }
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.