# Stop Repeating Yourself 2: Using Test Fixtures with AGP

DevFeed: [Stop Repeating Yourself 2: Using Test Fixtures with AGP](<https://devfeed.tech/articles/stop-repeating-yourself-2-using-test-fixtures-with-agp-25115.md>)

Original publisher: [Read original article](<http://michaelevans.org/blog/2024/07/29/stop-repeating-yourself-2-using-test-fixtures-with-agp/>)

Author: Michael Evans

Published: 2024-07-29T23:43:27Z

Content type: tutorial

Language: en

Sources: [Gadget Habit](<https://devfeed.tech/sources/gadget-habit.md>)

Topics: [Android Gradle Plugin](<https://devfeed.tech/topics/android-gradle-plugin.md>), [Testing](<https://devfeed.tech/topics/testing.md>), [Gradle](<https://devfeed.tech/topics/gradle.md>), [build performance](<https://devfeed.tech/topics/build-performance.md>), [Mobile](<https://devfeed.tech/topics/mobile.md>)

Tags: [android-development](<https://devfeed.tech/tags/android-development.md>), [android-gradle-plugin](<https://devfeed.tech/tags/android-gradle-plugin.md>), [build](<https://devfeed.tech/tags/build.md>), [build-performance](<https://devfeed.tech/tags/build-performance.md>), [configuration](<https://devfeed.tech/tags/configuration.md>), [gradle](<https://devfeed.tech/tags/gradle.md>), [plugin](<https://devfeed.tech/tags/plugin.md>), [testing](<https://devfeed.tech/tags/testing.md>), [tests](<https://devfeed.tech/tags/tests.md>)

## AI overview

This tutorial explains how Android Gradle Plugin 8.5.0 adds native support for reusable test fixtures in modularized Android projects. It covers defining shared test utilities such as mocks, fakes, and test data, then consuming them from other modules.

## Source excerpt

Modern Android development often involves modularization to enhance build performance and maintainability. As you break down your app into multiple modules, sharing test utilities such as fixtures, mocks, or fakes between modules can become challenging. A few years ago I wrote about the concept of test fixtures, but at the time they weren't supported for Android modules. Thankfully, with Android Gradle Plugin (AGP) 8.5.0, Google introduced native support for test fixtures, streamlining this process significantly. What Are Test Fixtures? Test fixtures are reusable components such as test data, helper classes, or mocks that you can use to support your tests. Prior to AGP 8.5.0, sharing these utilities across modules often required workarounds like creating dedicated "test" modules or manually wiring dependencies. With AGP 8.5.0, the testFixtures feature makes it easier to declare and consume test fixtures directly from your modules. Setting Up Test Fixtures To enable test fixtures for a module, you need to include the testFixtures feature in your module's build.gradle.kts file. Here's how you can set it up: 1 2 3 4 5 6 7 8 9 android { // Enable test fixtures for the module testFixtures.enable = true } dependencies { // Declare dependencies for your test fixtures testFixturesImplementation("com.example:some-library:1.0.0") } The testFixtures source set is automatically created under the src directory: 1 2 3 4 5 6 7 8 9 module-name/ src/ main/ java/ testFixtures/ java/ kotlin/ test/ java/ You can now place reusable test utilities, such as mock data generators or fake implementations, inside the testFixtures directory. Consuming Test Fixtures Modules can consume test fixtures by declaring a dependency on the testFixtures configuration of another module. For example, if module-b needs to use the test fixtures from module-a, add the following dependency: 1 2 3 dependencies { testImplementation(testFixtures(project(":module-a"))) } Once this dependency is added, the test co