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]robolectric/robolectric — GitHub repository(2026-10-06)
- [2]Robolectric 4.17 — README(2026-10-06)
- [3]Robolectric 4.17 release(2026-10-06)
- [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
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
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
Run the Debug unit tests
Run local Debug unit tests and confirm the Robolectric test passes without starting an emulator.
./gradlew testDebugUnitTest
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
Categories
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
Related information
Write a related articleShare a guide or use case for this OSS in Markdown. Articles are published after administrator approval.
Explore next
- Mockito15,454 Stars
3 shared tag(s) · 2 shared category(s) · Same language
replace Java collaborators and keep unit tests focused
Java - JUnit7,057 Stars
3 shared tag(s) · 2 shared category(s) · Same language
Java/JVM testing built on Platform and Jupiter
Java - AndroidX Test1,226 Stars
3 shared tag(s) · 2 shared category(s) · Same language
build Android instrumented and UI tests with AndroidJUnitRunner, Espresso, and AndroidX Test Core
Java - MockK5,762 Stars
3 shared tag(s) · 2 shared category(s)
mock, stub, and verify Kotlin collaborators with coroutine and Android support
Kotlin - Apache JMeter9,552 Stars
2 shared tag(s) · 2 shared category(s) · Same language
load HTTP, JDBC, JMS, and other services to measure response time, throughput, and performance behavior
Java - Jest45,500 Stars
2 shared tag(s) · 2 shared category(s)
Combine assertions, mocks, watch mode, snapshots, coverage, and worker isolation in one JavaScript test runner
TypeScript
Report incorrect information
Tell us if any listing information is incorrect or outdated.