Test Fixtures and Shared Test Code
Use the java-test-fixtures plugin to share reusable test helpers, builders, and fakes across modules without leaking them into production code.
The Shared Test Code Problem
Multiple modules often need the same test helpers (builders, fakes, fixtures). Copy-pasting them is brittle, and putting them in main code ships test-only classes to production.
Enter Test Fixtures
Gradle ships the java-test-fixtures plugin, which adds a dedicated testFixtures source set whose code can be consumed by other modules tests.
plugins {
id("java-library")
id("java-test-fixtures")
}All lessons in this course
- Unit & Integration Testing
- Test Reports & Filtering
- Code Coverage & Static Analysis
- Test Fixtures and Shared Test Code