Samstag, 10. März 2018

Gradle Kotlin DSL: Using JUnit 5


Since I ended up spending a lot of time figuring out how to do certain things in the Kotlin DSL for Gradle, I decided to share my findings in a series of small posts.

On todays menu is JUnit 5 and the built-in support in Gradle 4.6. Use the following code snippet to enable JUnit 5 tests in your Gradle build:

tasks {    
    withType<Test>{        
        useJUnitPlatform()
    }
}

UPDATE:
Gradle 4.9 introduced a new API for creating tasks which reflects in the Gradle Kotlin DSL in Gradle 4.10.

Using the new API to configure tasks of type Test looks the following:
tasks {
    withType<Test>().configureEach {
        useJUnitPlatform()
    }
}

Alternatively the test task can be configured directly:
tasks {
    "test"(Test::class) {
        useJUnitPlatform()
    }
}
This is now possible because the invoke() function on Strings was changed to look up existing tasks.

Keine Kommentare:

Kommentar veröffentlichen