The Robolectric team is super excited to announce the first alpha release of Robolectric 4.0, as well as some new developments in the world of Robolectric and Android testing in general.


We’re collaborating closely with the Android Jetpack testing team to develop common APIs for writing Android tests that can run as both local (JVM-based) and on-device (instrumentation) tests. From 4.0 on, Robolectric will support Jetpack’s androidx.test APIs, starting with support for the AndroidJUnit4 test runner, ActivityTestRule, and Espresso for interacting with UI components.

A Robolectric 3.x style test:

class RobolectricTest {
  @Test fun clickingOnTitle_shouldLaunchEditAction() {
    val activity = Robolectric.setupActivity(

Robolectric 4.x/instrumentation test:

class OnDeviceTest {
  @get:Rule val rule = ActivityTestRule(

  @Test fun clickingOnTitle_shouldLaunchEditAction() {

As you can see, many of the idioms common in instrumentation tests are now supported by Robolectric tests. In the near future we’ll be expanding androidx.test support on Robolectric, as well as introducing some Robolectric-originated testing paradigms to traditional instrumentation tests.

Binary Resources

In conjunction with Android Studio 3.2, Robolectric can now use resources processed using the Android build toolchain, and loads and handles those resources using the same logic as on an actual Android device. Robolectric’s old idiosyncratic resource handling mode is still available for projects not yet using the latest version of the build toolchain.

To enable the use of toolchain-processed resources in Robolectric tests, make sure you’re using Android Gradle Plugin version or higher, and add the following to your


Release Notes

Release notes are available here. Robolectric 4.0 is currently in alpha release, meaning that it is not yet feature-complete, and APIs are likely to change before the final release. Use with caution.

As always, thanks for your pull requests, bug reports, ideas and questions! 💯

Your Robolectric maintainers,,, and