How to convert testOptions.unitTests.all to gradle Kotlin dsl
Asked Answered
R

3

9

How this code should be translated from Groovy to Kotlin DSL in Gradle?

testOptions.unitTests.all {
    testLogging {
        exceptionFormat = "full"
        events "passed", "failed", "standardError"
        showCauses true
        showExceptions true
    }
}
Rule answered 1/10, 2020 at 17:18 Comment(0)
U
5

Use this:

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))
}
Unskilled answered 3/10, 2020 at 8:43 Comment(3)
What about includeAndroidResources?Sharmainesharman
Any idea about "None of the following functions can be called with the arguments supplied:" error?Thadthaddaus
@Sharmainesharman use isIncludeAndroidResources instead.Vesicant
V
0

I've got this error when I used "all"

None of the following functions can be called with the arguments supplied:

and by applying this code the error is gone :

    tasks.withType<Test>().all(KotlinClosure1<Test, Test>({
      

the complete code is here :

  testOptions.unitTests.apply {
    tasks.withType<Test>().all(KotlinClosure1<Test, Test>({
      apply {
        testLogging.exceptionFormat = TestExceptionFormat.FULL
        testLogging.events = setOf(
          TestLogEvent.PASSED,
          TestLogEvent.FAILED,
          TestLogEvent.STANDARD_ERROR,
          TestLogEvent.STANDARD_OUT,
          TestLogEvent.SKIPPED
        )
        testLogging.showCauses = true
        testLogging.showExceptions = true
      }
    }, this))
  }
Viewless answered 19/7 at 9:35 Comment(0)
L
-1

This is a cleaner version of the accepted answer:

testOptions {
    unitTests {
        isReturnDefaultValues = true
        isIncludeAndroidResources = true
      
        all {
            it.apply {
            testLogging {
                events("started", "passed", "skipped", "failed")
            }
        }
    }
}
Lambertson answered 9/1 at 0:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.