# Implementing a task that runs tests Sample

version 9.2.0-20250816005724+0000

- Groovy DSL

- Kotlin DSL

| You can open the samples inside an IDE using the IntelliJ native importer or Eclipse Buildship.

This sample shows how to create a plugin with a custom task that generates test events like the built-in `Test` task for JVM-based tests. The plugin is packaged via an included build.

This sample is intended to demonstrate how a platform provider, like Android or Kotlin Multiplatform, would use a low-level API to generate test events.

build.gradle.kts

    plugins {
        id("com.example.custom-test")
    }

    version = "1.0.2"

settings.gradle.kts

    rootProject.name = "custom-test-task"
    includeBuild("plugin")
    includeBuild("consumer")

build.gradle

    plugins {
        id 'com.example.custom-test'
    }

    version = '1.0.2'

settings.gradle

    rootProject.name = 'custom-test-task'
    includeBuild('plugin')
    includeBuild('consumer')

This sample contains two parts:

- The `custom-test-task` plugin, which defines a custom task that generates test events.

- The `consumer` build, which creates a Tooling API client to receive the test events.

| The `consumer` requires Java 21.

Run `gradle test` to run the custom test task. By default, no tests will fail and nothing will appear in the console log.

Run `gradle test --fail` to run the custom test task with failing tests. The console log will show the test events.

Run `gradle :consumer:run` to run the Tooling API client. The client will run `gradle test`, like above and print out any received test events.

As a platform provided for an ecosystem, you would create custom test tasks and use the `TestEventReporter` APIs to generate test events.

As a tooling integrator, like an IDE, you would use the Tooling API client to receive test events and display them as appropriate to the user.

For more information, see Gradle Plugins reference chapter.