GeezerVison is showing docs.gradle.org — The Java Test Fixtures Plugin
The Java Test Fixtures Plugin
version 9.9.3
The Java Test Fixtures plugin (plugin id: java-test-fixtures) adds support for producing and consuming test fixtures — shared test helper code such as fake implementations, test data builders, or base classes that are used by the project’s own tests and can also be consumed by other projects.
Despite the name, fixtures may be written in any supported JVM language, not only Java.
For a task-oriented guide — producing, consuming, and publishing fixtures — see Test fixtures in Testing in Java & JVM projects.
Apply the plugin alongside a JVM library or application plugin:
build.gradle.kts
plugins {
`java-library`
`java-test-fixtures`
}
build.gradle
plugins {
id 'java-library'
id 'java-test-fixtures'
}
-
creates a testFixtures source set and a corresponding feature exposing a <group>:<name>-test-fixtures capability;
-
makes the fixtures depend on the main component, and the project’s own test suite depend on the fixtures — both by convention, so no wiring is required;
-
when the Java Plugin is applied, exposes the fixtures to consumers as additional variants of the project’s component.
src/testFixtures/java
-
Test fixture source files.
src/testFixtures/resources
-
Test fixture resources.
The plugin adds a set of configurations for the testFixtures source set, mirroring those of a normal Java library: the fixtures get their own api/implementation/compileOnly/compileOnlyApi/runtimeOnly declarable configurations, their own consumable elements, and their own resolvable classpaths.
|
|
Applying this plugin also wires up two dependencies for you automatically:
-
testFixturesApi gets an implicit dependency on the project itself, so the fixtures can use the project’s own main classes.
-
The test source set’s testImplementation configuration (added by the Java Plugin) gets an implicit testFixtures(project(…)) dependency on this project, so your tests can use the fixtures without declaring anything yourself.
|
| Configuration name |
Role |
Description |
testFixturesApi
|
Declarable |
Dependencies exported to consumers of the fixtures (and to the fixtures' own compilation). |
testFixturesImplementation (extends testFixturesApi)
|
Declarable |
Dependencies used internally by the fixtures and not exposed to consumers. |
testFixturesCompileOnly (extends testFixturesCompileOnlyApi)
|
Declarable |
Compile-time-only dependencies of the fixtures, not exposed to consumers or at runtime. |
testFixturesCompileOnlyApi
|
Declarable |
Compile-time-only dependencies of the fixtures that are also visible to consumers at compile time. |
testFixturesRuntimeOnly
|
Declarable |
Runtime-only dependencies of the fixtures. |
| Configuration name |
Role |
Description |
testFixturesApiElements (extends testFixturesApi, testFixturesCompileOnlyApi)
|
Consumable |
The elements exposed to consumers that compile against the fixtures. |
testFixturesRuntimeElements (extends testFixturesImplementation, testFixturesRuntimeOnly)
|
Consumable |
The elements exposed to consumers that run against the fixtures. |
| Configuration name |
Role |
Description |
testFixturesCompileClasspath (extends testFixturesCompileOnly, testFixturesImplementation)
|
Resolvable |
The classpath used when compiling the fixtures. |
testFixturesRuntimeClasspath (extends testFixturesRuntimeOnly, testFixturesImplementation)
|
Resolvable |
The classpath used to run the fixtures. |
build.gradle.kts
dependencies {
testImplementation(testFixtures(project(":lib")))
}
build.gradle
dependencies {
testImplementation(testFixtures(project(":lib")))
}