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

Mat*_*zuk 9 gradle android-gradle-plugin gradle-kotlin-dsl

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

testOptions.unitTests.all {
    testLogging {
        exceptionFormat = "full"
        events "passed", "failed", "standardError"
        showCauses true
        showExceptions true
    }
}
Run Code Online (Sandbox Code Playgroud)

Sau*_*rat 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))
}
Run Code Online (Sandbox Code Playgroud)

  • 那“includeAndroidResources”呢? (3认同)
  • @IgorGanapolsky 使用 `isInincludeAndroidResources` 代替。 (2认同)