Introduce Robolectric Test

Why Robolectric?

Current Problems

  • Most tests are Android instrumentation tests, which are slow and require an emulator or device

  • Test execution takes several minutes due to emulator startup and app installation

  • CI setup is complex and resource-heavy

  • Android-dependent logic (Context, Resources, Fragments) is hard to unit test

Proposed Solution: Use Robolectric for JVM-based Android testing.


What is Robolectric?

Robolectric enables unit tests on the JVM with Android framework support.

  • Runs on the JVM without an emulator

  • Executes tests in seconds

  • Supports Android components such as Context, Resources, Activities, and Fragments

  • Integrates with JUnit

Robolectric is already partially used in the project (e.g., FeedDiscovererTest, ShownotesCleanerTest).


Key Benefits

Speed

  • Instrumentation tests: ~1–2 minutes per test

  • Robolectric tests: ~1–2 seconds per test

  • Results in 30–60x faster execution

No Emulator Dependency

  • Eliminates emulator/device requirements

  • Simplifies local development and CI pipelines

Android API Support

  • Enables testing of Android-dependent logic in unit tests

  • Suitable for utilities, ViewModels, and data-processing components

CI-Friendly

  • Tests can run with a simple ./gradlew test

  • Faster, more stable, and easier to maintain CI pipelines


Current Test State

  • Unit tests (test/): very limited

  • Instrumentation tests (androidTest/): majority of the test suite

This leads to slow feedback cycles and poor scalability.


Migration Strategy

Phase 1: Identify Candidates

Best suited for Robolectric:

  • Utility and helper classes

  • ViewModels and presenters

  • Data processing and parsing logic

  • Database tests using Robolectric SQLite

Not suitable:

  • Full UI and interaction tests

  • Hardware-dependent features

Phase 2: Migrate High-Value Tests

  • Move selected instrumentation tests to Robolectric

  • Focus on business logic and Android API usage

Phase 3: Expand Coverage

  • Add new Robolectric tests by default

  • Retain a minimal set of instrumentation tests for end-to-end UI flows


Recommendation

Begin by migrating 2–3 non-UI instrumentation tests as a proof of concept.
Measure execution time and CI improvements, then expand gradually.

This approach reduces test time, simplifies CI, and improves developer productivity without increasing risk.


If you want, I can now:

  • Reduce this further to a one-page RFC

  • Tailor it specifically for AntennaPod maintainers

  • Align it with an MVI-based testing strategy

Please don’t open duplicate discussions on both forum and GitHub. This makes it harder to follow them because the replies will be scattered across different places

1 Like

That sounds great! I know nothing about programming or developing, however I can see that many present issues will be fixed by that “procedure”.

That’s a fair point about the double-posting, I’ll stick to the GitHub thread for the technical bits! I really think introducing Robolectric would be a huge win for the CI pipeline - running unit tests that need Android dependencies without an emulator would speed up PR reviews quite a bit. Looking forward to seeing where the discussion goes on GitHub.

Would you have a link to the GitHub issue @JannieGen ?

1 Like

That’s why I couldn’t find it, it’s closed :slight_smile: