Skip to content

dataconnect: add gradle plugin that enables sharing code from src/test to src/androidTest#8098

Open
dconeybe wants to merge 6 commits intomainfrom
dconeybe/dataconnect/SharedWithAndroidTest
Open

dataconnect: add gradle plugin that enables sharing code from src/test to src/androidTest#8098
dconeybe wants to merge 6 commits intomainfrom
dconeybe/dataconnect/SharedWithAndroidTest

Conversation

@dconeybe
Copy link
Copy Markdown
Contributor

@dconeybe dconeybe commented May 6, 2026

This PR introduces a new Gradle plugin that enables sharing test utilities between unit tests (src/test) and instrumentation tests (src/androidTest). It allows developers to annotate Kotlin files with @file:SharedWithAndroidTest, which the plugin will automatically copy into the androidTest generated sources directory during the build process.

Highlights

  • Shared Test Utilities Plugin: Created a new Gradle plugin (com.google.firebase.dataconnect.sharedtest) to facilitate sharing code between unit and instrumentation tests.
  • Code Generation Task: Implemented a CopySharedWithAndroidTestFiles task to recursively search for files annotated with @file:SharedWithAndroidTest and copy them to the androidTest source set.
  • Custom Annotation: Added a @SharedWithAndroidTest annotation to mark source files intended for sharing across test environments.
Changelog
  • firebase-dataconnect.gradle.kts
    • Applied the new com.google.firebase.dataconnect.sharedtest plugin.
  • build.gradle.kts
    • Registered the com.google.firebase.dataconnect.sharedtest plugin.
  • CopySharedWithAndroidTestFiles.kt
    • Added a Gradle task that copies files annotated with @file:SharedWithAndroidTest from the src/test directory to a generated androidTest directory.
  • SharedWithAndroidTestPlugin.kt
    • Added the plugin implementation that registers the CopySharedWithAndroidTestFiles task and hooks it into the androidTest source sets.
  • SharedWithAndroidTest.kt
    • Added the @SharedWithAndroidTest file-level annotation used to mark code to be shared.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

@dconeybe
Copy link
Copy Markdown
Contributor Author

dconeybe commented May 6, 2026

/gemini review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 6, 2026

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Gradle plugin, com.google.firebase.dataconnect.sharedtest, designed to share test utilities between unit tests and Android instrumentation tests. It includes a custom Gradle task that identifies Kotlin files annotated with @file:SharedWithAndroidTest in the unit test source set and copies them to a generated source directory for androidTest. Review feedback suggests replacing a risky null assertion with a safer check in the plugin implementation, removing redundant manual directory cleanup logic handled automatically by Gradle's @OutputDirectory, and improving the robustness of the annotation detection logic to avoid false positives.

@dconeybe
Copy link
Copy Markdown
Contributor Author

dconeybe commented May 6, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Gradle plugin, com.google.firebase.dataconnect.sharedtest, which enables sharing test utilities between unit tests and Android instrumentation tests by copying annotated Kotlin files into the androidTest source set. The review feedback identifies two critical improvements for the CopySharedWithAndroidTestFiles task: using relative paths in generated headers to maintain Gradle build cache reproducibility and clearing the output directory before execution to prevent stale files from persisting when annotations are removed.

… files, to avoid defeating build caches [skip actions]
@dconeybe
Copy link
Copy Markdown
Contributor Author

dconeybe commented May 6, 2026

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new Gradle plugin, com.google.firebase.dataconnect.sharedtest, designed to share test utilities between unit tests and Android instrumentation tests. It includes a custom Gradle task, CopySharedWithAndroidTestFiles, which scans for Kotlin files annotated with @file:SharedWithAndroidTest and copies them into the generated source sets for androidTest. Feedback suggests clearing the output directory before copying to avoid stale files and marking the input directory as optional to prevent build failures when the source directory is absent.

@dconeybe dconeybe changed the title dataconnect: add gradle plugin that enables sharing testutil code in src/test with code in src/androidTest dataconnect: add gradle plugin that enables sharing code from src/test to src/androidTest May 6, 2026
@dconeybe dconeybe marked this pull request as ready for review May 6, 2026 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant