google / ground-android

Ground mobile data collection app for Android
http://groundplatform.org
Apache License 2.0
244 stars 114 forks source link

[Top code health] Add test coverage for all critical Android features #2134

Open gino-m opened 9 months ago

gino-m commented 9 months ago

Consider refactoring use cases into FooUseCase classes as we go.

This will likely also involve refactoring view logic out of fragments into view models to make more testable.

Full list TBD.

sufyanAbbasi commented 5 months ago

Approach:

  1. List out all the major features of the app then categorize them into priorities for test coverage.
  2. For each major feature, identify the files that belong to each feature.
  3. Run the test coverage tool and/or scan the tests to make sure that major edgecases and behaviors are addressed.
  4. Keep going until all files identified in the "major features" list have 100% test coverage.
sufyanAbbasi commented 5 months ago

A list of essential features flows:

  1. Sign-in/Sign-out state transitions
    1. Load and accept Terms of Service
  2. "Select a Survey" menu renders, shows and sets offline status
  3. Survey load and sync from remote
  4. Homescreen interactions:
    1. Nav menu items render, "Switch survey" triggers "select a survey" menu
    2. Layer menu renders, changes base maps, and toggling offline-imagery shows offline tiles.
  5. Home screen map interactions:
    1. Location lock triggers map location change
    2. Zoom level shows "zoom-in" message for ad-hoc and predetermined geometries.
    3. Zooming in shows the LOI cards, button click triggers task start (ad-hoc LOI and predetermined ones)
  6. Each task type and their behavior
    1. Capture Location (with location lock enabled)
    2. Drop pin (with instructions)
    3. Draw area (with instructions)
    4. Text
    5. Multiple choice (checkbox and radio, with other)
    6. Photo
    7. Number
    8. Date
    9. Time
    10. Conditional tasks
  7. Data upload to remote (workers)
  8. Offline-imagery loads and saves tiles from server
  9. Sync Status renders web worker status
  10. Settings

Other critical things to test:

  1. Offline interactions and sync when online
  2. Screen rotations
sufyanAbbasi commented 4 months ago

If anyone is running into test failures related to Bad return type converting color resources, try the instructions here: https://github.com/robolectric/robolectric/issues/3023#issuecomment-325365800

In the new Android Studio, I got it to work by clicking these buttons and setting the coverage runner as "JaCoCo" instead of the "IntelliJ IDE"

Screenshot 2024-05-16 at 5 37 50 PM Screenshot 2024-05-16 at 5 38 07 PM