Skip to content

Cleanup test setup#3572

Merged
andreia-ferreira merged 4 commits intomasterfrom
andreia/cleanup-tests
Feb 24, 2026
Merged

Cleanup test setup#3572
andreia-ferreira merged 4 commits intomasterfrom
andreia/cleanup-tests

Conversation

@andreia-ferreira
Copy link
Collaborator

@andreia-ferreira andreia-ferreira commented Feb 20, 2026

BaseHiltTest currently holds a composeTestRule, which adds unnecessary overhead to tests that don't need to test anything related to the UI. That may have a slight impact on runtime for non-UI tests but also it may make it harder for future modularization.

This PR refactors this setup by:

  • removing the composeTestRule from the base test class and moved it only to tests that actually need it
  • adding TestResourcesHelper to provide resources without requiring createAndroidComposeRule
  • cleaned up BaseHiltTest usage to decouple it from tests that don't need it (eg. pure compose tests)

@shobhitagarwal1612 PTAL?

@auto-assign auto-assign bot requested a review from gino-m February 20, 2026 10:56
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @andreia-ferreira, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request streamlines the test infrastructure by decoupling Compose UI tests from the main Hilt-based test class. This change improves test isolation and reduces boilerplate by allowing individual Compose tests to manage their own ComposeTestRule and utilize a new helper for string resource access. The refactoring also updates the TaskFragmentRunner to be more flexible, enhancing the overall maintainability and clarity of the test suite.

Highlights

  • Test Setup Decoupling: Decoupled Compose-based UI tests from the BaseHiltTest class and the HiltAndroidTest annotation, allowing them to manage their own ComposeTestRule instances.
  • Test Resource Helper: Introduced a new TestResourcesHelper.kt file with a getString utility function to simplify accessing string resources within tests without needing an Activity context.
  • TaskFragmentRunner Refactoring: Refactored TaskFragmentRunner to directly accept a ComposeContentTestRule, removing its dependency on BaseHiltTest's composeTestRule.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • app/src/test/java/org/groundplatform/android/BaseHiltTest.kt
    • Removed createComposeRule import and composeTestRule property.
    • Modified runWithTestDispatcher and closeDb functions to no longer be open.
  • app/src/test/java/org/groundplatform/android/TestResourcesHelper.kt
    • Added new file containing a getString utility function for simplified resource access in tests.
  • app/src/test/java/org/groundplatform/android/ui/basemapselector/BasemapSelectorScreenTest.kt
    • Imported createComposeRule and added it as a local @Rule.
    • Removed composeTestRule from BaseHiltTest.
  • app/src/test/java/org/groundplatform/android/ui/components/PermissionDeniedDialogTest.kt
    • Removed ComponentActivity import, HiltAndroidTest annotation, and BaseHiltTest inheritance.
    • Replaced createAndroidComposeRule with createComposeRule.
    • Updated string resource access to use the new getString helper.
  • app/src/test/java/org/groundplatform/android/ui/datacollection/DataCollectionFragmentTest.kt
    • Imported createComposeRule and added it as a local @Rule.
    • Updated runner() instantiation to pass the new composeTestRule.
  • app/src/test/java/org/groundplatform/android/ui/datacollection/TaskFragmentRunner.kt
    • Imported ComposeContentTestRule and added it as a constructor parameter.
    • Updated all internal calls from baseHiltTest.composeTestRule to use the new composeTestRule parameter.
  • app/src/test/java/org/groundplatform/android/ui/datacollection/components/TaskButtonTest.kt
    • Removed ComponentActivity import, HiltAndroidTest annotation, and BaseHiltTest inheritance.
    • Replaced createAndroidComposeRule with createComposeRule.
  • app/src/test/java/org/groundplatform/android/ui/datacollection/components/TaskFooterTest.kt
    • Removed ComponentActivity import, HiltAndroidTest annotation, and BaseHiltTest inheritance.
    • Replaced createAndroidComposeRule with createComposeRule.
  • app/src/test/java/org/groundplatform/android/ui/datacollection/components/UriImageTest.kt
    • Imported createComposeRule and added it as a local @Rule.
  • app/src/test/java/org/groundplatform/android/ui/datacollection/tasks/BaseTaskFragmentTest.kt
    • Imported ComponentActivity and createAndroidComposeRule.
    • Added composeTestRule as a local @Rule.
    • Updated runner() instantiation to pass the new composeTestRule.
  • app/src/test/java/org/groundplatform/android/ui/datacollection/tasks/instruction/InstructionTaskFragmentTest.kt
    • Removed ComponentActivity import and createAndroidComposeRule.
    • Removed composeTestRule from BaseTaskFragmentTest.
  • app/src/test/java/org/groundplatform/android/ui/datacollection/tasks/multiplechoice/MultipleChoiceItemViewTest.kt
    • Removed HiltAndroidTest annotation and BaseHiltTest inheritance.
    • Imported createComposeRule and added it as a local @Rule.
  • app/src/test/java/org/groundplatform/android/ui/datacollection/tasks/photo/PhotoTaskScreenTest.kt
    • Removed HiltAndroidTest annotation and BaseHiltTest inheritance.
    • Imported createComposeRule and added it as a local @Rule.
  • app/src/test/java/org/groundplatform/android/ui/datacollection/tasks/time/TimeTaskFragmentTest.kt
    • Removed blank line.
  • app/src/test/java/org/groundplatform/android/ui/home/AboutFragmentTest.kt
    • Removed comment explaining composeTestRule and updated its declaration to no longer be an override.
  • app/src/test/java/org/groundplatform/android/ui/home/DataSharingTermsDialogTest.kt
    • Removed ComponentActivity import, HiltAndroidTest annotation, and BaseHiltTest inheritance.
    • Replaced createAndroidComposeRule with createComposeRule.
    • Updated string resource access to use the new getString helper.
  • app/src/test/java/org/groundplatform/android/ui/home/HomeScreenFragmentTest.kt
    • Removed comment explaining composeTestRule and updated its declaration to no longer be an override.
  • app/src/test/java/org/groundplatform/android/ui/home/mapcontainer/HomeScreenMapContainerScreenTest.kt
    • Removed ComponentActivity import, HiltAndroidTest annotation, and BaseHiltTest inheritance.
    • Replaced createAndroidComposeRule with createComposeRule.
    • Updated string resource access to use the new getString helper.
  • app/src/test/java/org/groundplatform/android/ui/home/mapcontainer/jobs/JobMapComponentTest.kt
    • Removed ComponentActivity import, HiltAndroidTest annotation, and BaseHiltTest inheritance.
    • Replaced createAndroidComposeRule with createComposeRule.
    • Updated string resource access to use the new getString helper.
  • app/src/test/java/org/groundplatform/android/ui/home/mapcontainer/jobs/LoiJobSheetTest.kt
    • Removed ComponentActivity import, HiltAndroidTest annotation, and BaseHiltTest inheritance.
    • Replaced createAndroidComposeRule with createComposeRule.
    • Updated string resource access to use the new getString helper.
  • app/src/test/java/org/groundplatform/android/ui/main/MainActivityTest.kt
    • Imported createComposeRule and added it as a local @Rule.
  • app/src/test/java/org/groundplatform/android/ui/offlineareas/OfflineAreasFragmentTest.kt
    • Imported createComposeRule and added it as a local @Rule.
  • app/src/test/java/org/groundplatform/android/ui/offlineareas/selector/DownloadProgressDialogTest.kt
    • Removed ComponentActivity import.
    • Replaced createAndroidComposeRule with createComposeRule.
    • Updated string resource access to use the new getString helper.
  • app/src/test/java/org/groundplatform/android/ui/offlineareas/selector/OfflineAreaSelectorFragmentTest.kt
    • Updated composeTestRule declaration to no longer be an override.
  • app/src/test/java/org/groundplatform/android/ui/signin/SignInFragmentTest.kt
    • Imported createComposeRule and added it as a local @Rule.
  • app/src/test/java/org/groundplatform/android/ui/signin/SignInScreenTest.kt
    • Removed HiltAndroidTest annotation and BaseHiltTest inheritance.
    • Imported createComposeRule and added it as a local @Rule.
    • Replaced runWithTestDispatcher with runTest.
    • Added MockitoAnnotations.openMocks(this) in setUp().
  • app/src/test/java/org/groundplatform/android/ui/startup/StartupScreenTest.kt
    • Removed HiltAndroidTest annotation and BaseHiltTest inheritance.
    • Imported createComposeRule and added it as a local @Rule.
    • Added MockitoAnnotations.openMocks(this) in setUp().
    • Replaced runTest with runTest.
  • app/src/test/java/org/groundplatform/android/ui/surveyselector/SurveySelectorFragmentTest.kt
    • Updated composeTestRule declaration to no longer be an override.
  • app/src/test/java/org/groundplatform/android/ui/surveyselector/components/SurveyCardItemTest.kt
    • Removed ComponentActivity import, HiltAndroidTest annotation, and BaseHiltTest inheritance.
    • Replaced createAndroidComposeRule with createComposeRule.
    • Updated string resource access to use the new getString helper.
  • app/src/test/java/org/groundplatform/android/ui/surveyselector/components/SurveySectionListTest.kt
    • Removed ComponentActivity import, HiltAndroidTest annotation, and BaseHiltTest inheritance.
    • Replaced createAndroidComposeRule with createComposeRule.
    • Updated string resource access to use the new getString helper.
  • app/src/test/java/org/groundplatform/android/ui/syncstatus/SyncStatusFragmentTest.kt
    • Imported createComposeRule and added it as a local @Rule.
  • app/src/test/java/org/groundplatform/android/ui/tos/TermsOfServiceFragmentTest.kt
    • Removed comment explaining composeTestRule and updated its declaration to no longer be an override.
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 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 counter productive. 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
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

The pull request successfully cleans up the test setup by localizing composeTestRule and removing unnecessary Hilt dependencies from pure UI component tests. It also introduces a helpful getString utility for accessing resources in tests. I've suggested a few improvements for consistency and better mock management in the newly refactored tests.

@codecov
Copy link

codecov bot commented Feb 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 71.02%. Comparing base (267c53d) to head (f086bd4).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3572      +/-   ##
============================================
- Coverage     71.03%   71.02%   -0.02%     
  Complexity     1631     1631              
============================================
  Files           331      331              
  Lines          8956     8956              
  Branches        998      998              
============================================
- Hits           6362     6361       -1     
- Misses         1998     1999       +1     
  Partials        596      596              

see 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@shobhitagarwal1612 shobhitagarwal1612 left a comment

Choose a reason for hiding this comment

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

Love the cleaner test setup! Thanks for the refactor.
Does this have any impact on the total runtime of the tests?

@andreia-ferreira
Copy link
Collaborator Author

Thanks! On local tests runs I only noticed a slight decrease in the average test runtime (around 10s or so), so nothing dramatic :)

However, I'm marking this PR as a draft for now because I noticed the changes might introduce some flakiness in certain tests which I want to investigate better

@andreia-ferreira andreia-ferreira marked this pull request as draft February 20, 2026 13:36
@andreia-ferreira andreia-ferreira marked this pull request as ready for review February 24, 2026 11:48
@andreia-ferreira
Copy link
Collaborator Author

andreia-ferreira commented Feb 24, 2026

after #3580 this PR is now safe to merge. Since those changes removed the static dispatcher from TestCoroutineDispatchersModule , leftover tasks or uncaught exceptions from previous tests no longer persist and there's less risk of cross-test state leaks

The flakiness only surfaced after this decoupling refactor, which likely changed enough about the test setup to make the pre-existing issue visible. After the dispatchers fix that flakiness doesn't occur anymore

@andreia-ferreira andreia-ferreira merged commit 6f4620e into master Feb 24, 2026
9 checks passed
@andreia-ferreira andreia-ferreira deleted the andreia/cleanup-tests branch February 24, 2026 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants