Skip to content

test: Port tests to Roboelectric - #94

Merged
williscool merged 24 commits into
masterfrom
copilot/port-test-suite-to-roboelectric
Nov 29, 2025
Merged

williscool merged 24 commits into
masterfrom
copilot/port-test-suite-to-roboelectric

Conversation

Copilot AI commented Nov 27, 2025 •

Copy link
Copy Markdown

PR: Port Instrumentation Tests to Robolectric Unit Tests

Summary

Ports 10 instrumentation test files (~50 tests) to Robolectric unit tests, enabling fast local testing (~30s vs ~ 7 minutes) while maintaining faithful coverage of core functionality.

14x speed improvement!

Key Changes

Production Code (minimal, per established pattern):

  • ApplicationController.registerNewEvent() - Added optional db: EventsStorageInterface? parameter for dependency injection
  • ApplicationController.notificationManager - Changed to lazy initialization (by lazy) to allow test interception

New Test Utilities:

  • MockMonitorStorage - In-memory MonitorStorageInterface implementation
  • MockEventsStorage - In-memory EventsStorageInterface implementation
  • TestStorageFactory - Singleton factory for mock storage instances
  • Extended MockCalendarProvider with in-memory calendar/event/reminder storage
  • Extended MockContextProvider with permission grants and SharedPreferences handling

New Robolectric Test Files (10 files):

File Tests Notes
EventDismissRobolectricTest 17 +1 toast test
OriginalEventDismissRobolectricTest 6 +3 additional scenarios
ComponentIsolationRobolectricTest 5 Full parity
CalendarProviderBasicRobolectricTest 7 Full parity
CalendarProviderEventRobolectricTest 8 Full parity
CalendarProviderReminderRobolectricTest 8 Full parity
CalendarBackupRestoreRobolectricTest 5 Full parity
SimpleCalendarMonitoringRobolectricTest 3 Tests real registerNewEvent
FixturedCalendarMonitorServiceRobolectricTest 5 Full parity
CalendarTestFixtureExampleRobolectricTest 2 Full parity

Technical Approach

  1. Dependency Injection over Constructor Mocking - Following docs/dev_completed/constructor-mocking-android.md, avoided unreliable mockkConstructor/mockkStatic by adding optional parameters to production methods

  2. In-Memory Storage - Created mock storage implementations to avoid native SQLite library issues in JVM environment

  3. Settings Cache Clearing - Used reflection to clear ApplicationController.settings between tests to ensure test isolation

  4. Architecture Compatibility - Added try-catch for ShadowSQLiteConnection.setUseInMemoryDatabase() which throws on x86_64 in GitHub Actions

What's Tested

  • ✅ Real ApplicationController orchestration logic
  • ✅ Event registration (repeating/non-repeating)
  • ✅ Event dismissal flows
  • ✅ Calendar monitoring flow
  • ✅ Backup/restore logic
  • ✅ Calendar/event/reminder CRUD operations
  • ✅ Settings integration

Not Ported (by design)

Instrumentation tests remain the source of truth for:

  • Full end-to-end integration with real SQLite
  • Real Android CalendarContract interactions
  • Notification posting to system

ALSO! implements

https://github.com/endersonmenezes/free-disk-space

Original prompt

Can you keep going on porting the test suit to roboelectric?


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI changed the title [WIP] Port test suite to Robolectric framework Add Robolectric tests for storage layers and event records Nov 27, 2025
Copilot AI requested a review from williscool November 27, 2025 21:36
@williscool

Copy link
Copy Markdown
Owner

@copilot Can you see that latest ci run results? A few tests not working

@github-actions

Copy link
Copy Markdown

Build artifacts for PR #94 (commit 4edc40f) are available:

You can download these artifacts from the "Artifacts" section of the workflow run.

@github-actions

Copy link
Copy Markdown

Build artifacts for PR #94 (commit 4edc40f) are available:

You can download these artifacts from the "Artifacts" section of the workflow run.

Copilot AI commented Nov 27, 2025 •

Copy link
Copy Markdown
Author

@copilot Can you see that latest ci run results? A few tests not working

Fixed in 3766754. The tests were using EventMovedInTheCalendar but the correct enum value is AutoDismissedDueToCalendarMove. This was causing compilation failures in DismissedEventsStorageRobolectricTest.kt and OriginalEventDismissRobolectricTest.kt.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • dl.google.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java /usr/lib/jvm/temurin-17-jdk-amd64/bin/java -XX:MaxMetaspaceSize=1g -XX:+HeapDumpOnOutOfMemoryError --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED -Xmx8g -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-8.6-bin/afr5mpiioh2wthjmwnkmdsd5w/gradle-8.6/lib/gradle-launcher-8.6.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-8.6-bin/afr5mpiioh2wthjmwnkmdsd5w/gradle-8.6/lib/agents/gradle-instrumentation-agent-8.6.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 8.6 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@github-actions

github-actions Bot commented Nov 27, 2025 •

Copy link
Copy Markdown

Code Coverage Report

Overall Project 17.15% -0.06% ❌
Files changed 78.71% 🍏

Module Coverage
app 27.53% -0.03% 🍏
x8664Debug 6.89% -0.08% 🍏
Files
Module File Coverage
app ApplicationController.kt 51.49% -0.4% 🍏
x8664Debug ApplicationController.kt 34.88% -1.07% 🍏

@github-actions

Copy link
Copy Markdown

📊 Code Coverage Summary

Coverage Type Coverage
Overall null
Changed Files 100

View detailed coverage report

@github-actions

Copy link
Copy Markdown

📊 Code Coverage Summary

Coverage Type Coverage
Overall null
Changed Files 100

View detailed coverage report

@github-actions

Copy link
Copy Markdown

Build artifacts for PR #94 (commit 83fcf77) are available:

You can download these artifacts from the "Artifacts" section of the workflow run.

@github-actions

Copy link
Copy Markdown

Build artifacts for PR #94 (commit 83fcf77) are available:

You can download these artifacts from the "Artifacts" section of the workflow run.

@williscool

Copy link
Copy Markdown
Owner

@copilot Awesome! It builds now

@williscool

Copy link
Copy Markdown
Owner

@copilot Awesome! It builds now 88 tests completed, 66 failed

@williscool

Copy link
Copy Markdown
Owner

@copilot There are already some robo-electric tests that work and there is an implementation that gets around this look at the existing working tests

Copilot AI commented Nov 27, 2025

Copy link
Copy Markdown
Author

@copilot There are already some robo-electric tests that work and there is an implementation that gets around this look at the existing working tests

Fixed in c93ebd9. The storage tests I added were trying to instantiate real storage classes (DismissedEventsStorage, EventsStorage, MonitorStorage) which use the requery:sqlite-android native library incompatible with Robolectric.

I followed the pattern from the existing EventDismissRobolectricTest which uses mocked storage instances (mockk<DismissedEventsStorage>(relaxed = true)) instead of real ones.

Removed the failing tests. Kept EventAlertRecordTest (pure JVM, 18 tests) which doesn't need SQLite.

@github-actions

Copy link
Copy Markdown

📊 Code Coverage Summary

Coverage Type Coverage
Overall null
Changed Files 100

View detailed coverage report

@github-actions

Copy link
Copy Markdown

📊 Code Coverage Summary

Coverage Type Coverage
Overall null
Changed Files 100

View detailed coverage report

@github-actions

Copy link
Copy Markdown

Build artifacts for PR #94 (commit 55e2f5f) are available:

You can download these artifacts from the "Artifacts" section of the workflow run.

@github-actions

Copy link
Copy Markdown

Build artifacts for PR #94 (commit 7969ac6) are available:

You can download these artifacts from the "Artifacts" section of the workflow run.

@github-actions

Copy link
Copy Markdown

📊 Code Coverage Summary

Coverage Type Coverage
Overall null
Changed Files 100

View detailed coverage report

@github-actions

Copy link
Copy Markdown

Build artifacts for PR #94 (commit 1b43cb7) are available:

You can download these artifacts from the "Artifacts" section of the workflow run.

@github-actions

Copy link
Copy Markdown

📊 Code Coverage Summary

Coverage Type Coverage
Overall null
Changed Files 100

View detailed coverage report

@williscool williscool changed the title Add Robolectric tests for storage layers and event records test: Port tests to Roboelectric Nov 29, 2025
@github-actions

Copy link
Copy Markdown

Build artifacts for PR #94 (commit 83c8a6e) are available:

You can download these artifacts from the "Artifacts" section of the workflow run.

@williscool williscool left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

super excited for this port! way faster!

@williscool
williscool marked this pull request as ready for review November 29, 2025 19:16
@github-actions

Copy link
Copy Markdown

📊 Code Coverage Summary

Coverage Type Coverage
Overall 6.89
Changed Files 34.88

View detailed coverage report

@github-actions

Copy link
Copy Markdown

Build artifacts for PR #94 (commit 9712d29) are available:

You can download these artifacts from the "Artifacts" section of the workflow run.

…hing

- Add endersonmenezes/free-disk-space@v3 to integration-test job
- Fix SDK cache path: use /usr/local/lib/android/sdk/system-images/
  instead of non-existent ~/.android/sdk/
- Use stable cache key based on API level/arch instead of gradle
    hashes
- Align save/restore paths in common-setup and cache-update actions
@github-actions

Copy link
Copy Markdown

Build artifacts for PR #94 (commit ccd3602) are available:

You can download these artifacts from the "Artifacts" section of the workflow run.

@github-actions

Copy link
Copy Markdown

📊 Code Coverage Summary

Coverage Type Coverage
Overall 6.89
Changed Files 34.88

View detailed coverage report

@williscool williscool changed the title test: Port tests to Roboelectric test: Port tests to Roboelectric and setup endersonmenezes/free-disk-space Nov 29, 2025
@williscool williscool changed the title test: Port tests to Roboelectric and setup endersonmenezes/free-disk-space test: Port tests to Roboelectric Nov 29, 2025
@github-actions

Copy link
Copy Markdown

📊 Code Coverage Summary

Coverage Type Coverage
Overall 17.15
Changed Files 43.18

View detailed coverage report

@williscool
williscool merged commit fe89e06 into master Nov 29, 2025
10 checks passed
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