You can open this sample inside an IDE using the IntelliJ native importer, Eclipse Buildship.

This sample shows how to unit and functional test a Gradle plugin. The project is a simple Gradle plugin implemented in Java with a unit test using Gradle’s ProjectBuilder and a functional test using Gradle Test Kit.

build.gradle
plugins {
	id 'dev.gradleplugins.java-gradle-plugin' version '1.1'
	id 'dev.gradleplugins.gradle-plugin-unit-test' version '1.1'
	id 'dev.gradleplugins.gradle-plugin-functional-test' version '1.1'
}

gradlePlugin {
	plugins {
		helloWorld {
			id = 'com.example.hello'
			implementationClass = 'com.example.BasicPlugin'
		}
	}
}

repositories {
	mavenCentral()
}

test {
	dependencies {
		implementation spockFramework()
		implementation groovy()
	}
}

functionalTest {
	dependencies {
		implementation spockFramework()
		implementation groovy()
		implementation gradleTestKit()
	}
}
build.gradle.kts
plugins {
	id("dev.gradleplugins.java-gradle-plugin") version("1.1")
	id("dev.gradleplugins.gradle-plugin-unit-test") version("1.1")
	id("dev.gradleplugins.gradle-plugin-functional-test") version("1.1")
}

gradlePlugin {
	plugins {
		create("helloWorld") {
			id = "com.example.hello"
			implementationClass = "com.example.BasicPlugin"
		}
	}
}

repositories {
	mavenCentral()
}

test {
	dependencies {
		implementation(spockFramework())
		implementation(groovy())
	}
}

functionalTest {
	dependencies {
		implementation(spockFramework())
		implementation(groovy())
		implementation(gradleTestKit())
	}
}

To build and test the plugin:

$ ./gradlew check

BUILD SUCCESSFUL
9 actionable tasks: 9 executed

Gradle executes both test suites, which is a unit test and a functional test, as expected. The reports are available at their conventional location:

$ ls ./build/reports/tests
functionalTest
test

The build scan displays the test events:

Build scan showing the test events from both test suites.

For more information, see Gradle Plugin Development reference chapters and user manual chapter.