Skip to content

[FR]: Migrate project to testFixtures #451

Description

@SimonMarquis

Is there an existing issue for this?

  • I have searched the existing issues

Describe the problem

Even though test fixtures 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 modules 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

  • I agree to follow this project's Code of Conduct

Activity

  1. added 6 commits that reference this issue on Nov 19, 2022
    84eee4e
    1e5dadf
    ad50fb1
    c15ac2e
    e334016
    f6b8259
  2. JolandaVerhoef commented on Nov 20, 2022

    @JolandaVerhoef
    Collaborator

    This looks like an interesting addition, however I'd like to wait for support by Jetbrains (through https://youtrack.jetbrains.com/issue/KT-50667) before adding this to the project.

  3. SimonMarquis commented on Nov 20, 2022

    @SimonMarquis
    ContributorAuthor

    Just to clarify, testFixture are officially supported.
    The only bit that is not yet supported is exposing Kotlin sources from an AGP (com.android.application or com.android.library) module.
    But I can understand if we don't want to include this feature until it is completely supported 👍

  4. yogurtearl commented on Nov 15, 2023

    @yogurtearl
  5. SimonMarquis commented on Jun 23, 2024

    @SimonMarquis
    ContributorAuthor

    For anyone interested in updates, I've pushed a new PR that enables "almost" proper Android test fixtures thanks to AGP 8.5.0:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions