OSS TanbouSign in with GitHub

run Android unit tests on the JVM without starting a device or emulator

About these scores

OSS scale score is an unbounded metric that log-compresses and weights Stars, Watchers, Forks, and Contributors. Discovery score is the current OSS scale score minus the score at discovery. Update pace is commits in the last 30 days, growth momentum is the OSS scale score difference within the recent observation window, and OSS health is a 0–100 rating based on available recency, Community Health, and release data.

Stars
6,061
Primary language
Java
License
Not determined
Repository last updated
Oct 6, 2026
On this page

Overview

Robolectric is an Android unit-testing framework that simulates the Android environment inside the JVM. Tests can exercise Activities and Android APIs without starting a physical device or emulator.

Features and best fit

Based on official documentation; not hands-on tested · Content checked:

Key features

Exercise Android APIs from JVM tests

Robolectric simulates Android framework behavior so Activities, Views, and system APIs can be exercised as local JVM tests without waiting for a device to boot.

Sources: [2]

Combine Robolectric with AndroidX Test-style tests

The README example uses AndroidJUnit4 together with Robolectric.buildActivity to move an Activity through its lifecycle and assert UI behavior.

Sources: [2]

Best fit

Fits Android teams that want a short feedback loop for framework-dependent logic

It is useful when local tests need more Android behavior than plain JVM mocks provide, while avoiding an emulator for every unit-level check.

Sources: [2]

Before adoption

Review SDK 37 support, JDK configuration, and real-device differences

Robolectric 4.17 adds SDK 37 support. Its release notes warn that JDK 17 or newer may require jvmFlags configuration. Keep instrumented tests for behavior that depends on rendering, hardware, or OEM-specific platform details.

Sources: [3]

Official sources

  1. [1]robolectric/robolectric — GitHub repository(2026-10-06)
  2. [2]Robolectric 4.17 — README(2026-10-06)
  3. [3]Robolectric 4.17 release(2026-10-06)
  4. [4]Robolectric 4.17 — LICENSE(2026-10-06)
Supplemental curator note

Robolectric is useful for fast feedback on Android API-dependent logic without starting a device or emulator. Keep device or emulator instrumented tests for behavior that depends on the real platform implementation.

Try it in 3 steps

  1. 1

    Add Robolectric 4.17 and test dependencies

    Add Robolectric 4.17, JUnit 4, and the AndroidX Test JUnit extension to the Android module.

    testImplementation("junit:junit:4.13.2") testImplementation("org.robolectric:robolectric:4.17") testImplementation("androidx.test.ext:junit:1.3.0")
  2. 2

    Write a local Activity test

    Follow the ActivityController pattern from the README and advance the Activity lifecycle inside the JVM.

    @RunWith(AndroidJUnit4::class) class MyActivityTest { @Test fun launch() { Robolectric.buildActivity(MyActivity::class.java).use { controller -> val activity = controller.setup().get() check(activity != null) } } }
  3. 3

    Run the Debug unit tests

    Run local Debug unit tests and confirm the Robolectric test passes without starting an emulator.

    ./gradlew testDebugUnitTest
Check the official README

Growth

Growth trends · Last 30 days

6,061 Stars

Trend data is still being collected.

Development activity

Last 90 days · weekly

Commits (last 30 days)
43
Open PRs
100

Development activity is still being collected.

Built with

Categories and tags

GitHub data

GitHub dataView detailed GitHub data

GitHub Topics

  • android
  • robolectric
  • java
  • unit-testing
Stars
6,061
Forks
1,391
Watchers
187
Open issues
394
Contributors
201
Owner type
Organization
Primary language
Java
License
Not determined
Repository last updated
Oct 6, 2026
Write a related article

Share a guide or use case for this OSS in Markdown. Articles are published after administrator approval.

Report incorrect information

Tell us if any listing information is incorrect or outdated.

After reading this page, do you know what to do next?