android / android/nowinandroid

[FR]: Migrate project to testFixtures

Open
#451 4 comments 1 reaction 0 assignees View on GitHub
enhancement
Dominant language
Kotlin
Stars
21.8k
Forks
4.6k
Avg merge
19h 20m
Merged PRs (30d)
2

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the problem

Even though [test fixtures](https://docs.gradle.org/current/userguide/java_testing.html) are not completely supported by the Android Gradle Plugin (specifically with Kotlin sources) we can still benefit a lot from this feature on JVM modules, and this should definitely be part of Android dev's best practices!

### Describe the solution

This would remove **a lot** of code duplication and prevent unecessary hacks like shared `sourcesSet` and gradle fixtures `module`s that could impact build times, especially in large code bases.
In the current state of the code base, it sheds ~1000 lines of code.

At my current company, we chose to use `kotlin.Random` as receiver for these testFixtures to make them more explicit about their behavior (being random by default), but this can be changed here if needed.

Next steps will be to migrate:
- "test" modules: `:core:data-test`, `:core:datastore-test`, `:sync-test`
- fakes and test classes like `FakeStringDecoder`, `TestAuthorsRepository`, `TestNewsRepository`, `TestTopicsRepository`, `TestUserDataRepository`

These next steps could already be done, but would need to rewrite classes in Java to be visible, and I don't think this is a path we want to go for this project.
So I guess we'll wait for the full Android/Kotlin support.

### Additional context

_No response_

### Code of Conduct

- [X] I agree to follow this project's Code of Conduct

Contributor guide

Open the contributing guide

Research direction

Start with Gradle's testFixtures documentation, then inspect the listed modules: :core:data-test, :core:datastore-test, and :sync-test, along with the named fake and test classes. Determine whether current Android and Kotlin support permits migration without rewriting Java-visible classes; done means reducing the shared source-set and fixture-module code while preserving test fixture use.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.