Gradle Plugin Testing Strategies
You can open this sample inside an IDE using the IntelliJ native importer, Eclipse Buildship. |
This sample shows how to expand the testing coverage of a Gradle plugin to multiple Gradle distributions. The project is a simple Gradle plugin implemented in Java with a functional test using Gradle fixtures maintained by the Nokee team.
build.gradle
plugins {
id 'dev.gradleplugins.java-gradle-plugin' version '1.2'
id 'dev.gradleplugins.gradle-plugin-functional-test' version '1.2'
}
gradlePlugin {
plugins {
helloWorld {
id = 'com.example.hello'
implementationClass = 'com.example.BasicPlugin'
}
}
}
repositories {
mavenCentral()
}
functionalTest {
testingStrategies = [strategies.coverageForMinimumVersion, strategies.coverageForLatestGlobalAvailableVersion, strategies.coverageForLatestNightlyVersion]
dependencies {
implementation spockFramework()
implementation groovy()
implementation gradleFixtures() (1)
implementation gradleTestKit()
}
}
build.gradle.kts
plugins {
id("dev.gradleplugins.java-gradle-plugin") version("1.2")
id("dev.gradleplugins.gradle-plugin-functional-test") version("1.2")
}
gradlePlugin {
plugins {
create("helloWorld") {
id = "com.example.hello"
implementationClass = "com.example.BasicPlugin"
}
}
}
repositories {
mavenCentral()
}
functionalTest {
testingStrategies.set(listOf(strategies.coverageForMinimumVersion, strategies.coverageForLatestGlobalAvailableVersion, strategies.coverageForLatestNightlyVersion))
dependencies {
implementation(spockFramework())
implementation(groovy())
implementation(gradleFixtures()) (1)
implementation(gradleTestKit())
}
}
1 | The Nokee team maintains the Gradle fixtures which cover common testing scenarios and are testing strategy aware.
The Gradle executer will honour the selected testing strategy for the Test task.
Read the testing strategy section to learn more. |
To build and test the plugin:
$ ./gradlew check BUILD SUCCESSFUL 9 actionable tasks: 9 executed
Gradle executes the test suites for all testing coverage, which is minimum supported Gradle, latest released Gradle and latest nightly. The reports are available at their conventional location:
$ ls ./build/reports/tests functionalTestLatestGlobalAvailable functionalTestLatestNightly functionalTestMinimumGradle
The build scan displays the test events:
The developer can choose which coverage to execute directly from the IDE:
For more information, see Gradle Plugin Development reference chapters and user manual chapter.