Oct 11, 2018
Version 3.6.2

@xian xian released this Oct 5, 2018 · 10 commits to master since this release

Assets 2

Robolectric 4.0 brings support for the Android P (SDK 28) release, new and improved support and testing APIs for dozens of Android classes, initial support for some androidx-test APIs, and a complete rewrite of the resource handling code making it behave much more like a real Android device. This is a beta release: public APIs should be fairly stable, but expect to find some bugs here and there.

With the major version number bump to 4.0, we're making changes to some public APIs, detailed below. We're working on a migration tool to help convert your existing tests to be compatible with Robolectric 4.0.

New since 4.0-alpha-3

  • Support for binary resources mode in P.
  • Added support for androidx.test's ActivityScenario API.

API Changes

  • Most @Implementation methods in shadow classes are now protected instead of public. Tests should always prefer to call SDK methods directly on Android classes rather than on their shadows [issue #4007].
  • RuntimeEnvironment.application has been deprecated, use androidx.test.core.app.ApplicationProvider.getApplicationContext() instead.
  • AutoCloseable is now supported. In earlier versions of Robolectric, try-with-resources blocks would fail to call close() on the resource.
  • Bumped Android P to build 4913185.

New and improved SDK support and testing APIs for numerous Android classes, including:

  • ActivityManager.getAppTasks()
  • ApplicationPackageManager content providers, canRequestPackageInstalls()
  • AppOpsManager
  • AsyncQueryHandler
  • AudioManager.getActivePlaybackConfiguration()
  • BackupManager
  • BluetoothAdapter profile connection state and bond state
  • Build.getSerial()
  • CameraManager and CameraCharacteristics
  • Camera.Parameters preview sizes
  • CarrierConfigManager.getConfigForSubId()
  • ConnectivityManager support for NetworkCapabilities, requestNetwork().
  • ContentResolver.openOutputStream(), 'getSyncAdapterTypes()'
  • Context.bindServiceAsUser()
  • DevicePolicyManager.setUserProvisioningState()
  • EuiccManager
  • FontFamily
  • Improvements to AccessibilityNodeInfo
  • NotificationManager support for AutomaticZenRules
  • PackageManager.checkPermission() checks PackageInfo.requestedPermissionsFlags to determine if a permission is granted.
  • Path, PathMeasure, and PathParser
  • SensorManager
  • Service.stopSelfResult()
  • ShadowSensor.newInstance()
  • Sms
  • SubscriptionManager.getActiveSubscriptionInfoForSimSlotIndex(), getActiveSubscriptionInfoCount() etc., 'getDefaultSubscriptionId()'
  • SystemClock.elapsedRealtimeNanos() and currentNetworkTimeMillis()
  • TelecomManager.silenceRinger()
  • TelephonyManager.getSubscriberId(), getSimSerialNumber(), 'getVoiceNetworkType()'
  • TextToSpeech
  • Tile and TileService minimal implementation
  • TimeZoneFinder
  • UsbManager
  • UserManager now supports multiple users.
  • UserStatsManager test API: ShadowUserStatsManager.simulateTimeChange(); use EventBuilder can be used to return arbitrary events
  • VMRuntime.is64Bit(), ShadowVMRuntime.setIs64Bit(), ShadowBuild.setSupported64BitAbis()
  • WebStorage
  • WebView.saveState() and restoreState()
  • WifiManager.connect(int, ActionListener)
  • Fixed a bug in RoboCursor.getLong().
  • Fixed a deadlock related to saving preferences.
  • Improved support for Java 9.
  • Fixes to Looper.myLooper()
  • Support for color gamut and HDR in @Config(qualifiers).
  • Added subscribe and search functionality to ShadowMediaBrowserCompat. Also added easy ways to create MediaItems and get all created MediaItems with their parent-child relationships [thanks Jehron Petty and Noah Luddy!].
    • getRoot(), getItem(), subscribe(), and search() can only be called successfully after ShadowMediaBroswserCompat.connect() is called.
    • The default root id is root_id. This is what will be returned by getRoot() by default. The root id can be changed with setRootId(). Note that if the root is created with createMediaItem(), setRootId() must also be called with the same mediaId.
    • There is no getSessionToken() method in ShadowMediaBrowserCompat. Follow issue #3962 for updates.

New since Robolectric 3.8

Features

  • Support for the Android 28 API [Issue #3933]
  • Add errorprone/auto-refactoring support [Issue #3944]
  • Verify shadow @Implementation methods against SDKs [Issue #3952]
  • Support Espresso typeText [Issue #3919]
  • Add SupportFragmentController#setupFragment() [Issue #3911]
  • Shadow get/setNotificationPolicy on NotificationManager [Issue #3911]
  • Adds a simple Shadow for JobService so classes that extend it can call jobFinished() without crashing. [Issue #3911]
  • Add createSensorEvent and sendSensorEventToListeners to ShadowSensorManager [Issue #3911]
  • Make the result of WifiScanner#startScan() configurable. [Issue #3911]
  • Add functionality for setting the unbadged application icon in ShadowPackageManager [Issue #3919]
  • Support OnAlarmListener call in ShadowAlarmManager [Issue #3919]
  • Add ParameterizedRobolectricTestRunner#parameter annotation and remove dependency on XStream [Issue #3919]
  • Support CookieManager.removeAllCookies. [Issue #3919]
  • Add overloads to PendingIntent.send [Issue #3919]
  • Support retrieving the last message sent via Messenger [Issue #3919]
  • Add implementation for getAppStandbyBuckets and setAppStandbyBuckets to ShadowUsageStatsManager [Issue #3919]
  • Adding error behavior to ShadowGeocoder. [Issue #3919]
  • Add basic GLES20 support. [Issue #3924], [Issue #3944]
  • Add support for new LocationManager API in Android P [Issue #3924]
  • Add support to ShadowPowerManager to capture rebooting. [Issue #3924]
  • Add support for Parcel.read/writeBlob [Issue #3924]
  • Improve ShadowSoundPool adding the ability to query played sounds. [Issue #3944]
  • Add method to override system properties [Issue #3944]
  • Add BluetoothDevice#getUuids/setUuids [Issue #3944]
  • Enhance support for BluetoothGatt [Issue #3944]
  • Implement the newer AudioManager request and abandon audio focus api [Issue #3944]
  • Add ShadowPackageManager#addSystemSharedLibraryName [Issue #3944]
  • Add setMode and checkOpNotThrow (hidden) APIs to ShadowAppOpsManager [Issue #3944]
  • Update ShadowDebug to allow for method tracing. [Issue #3944]
  • Add setTimeZone method to ShadowAlarmManager [Issue #3944]
  • Add ShadowVisualVoicemailSms [Issue #3944]
  • Add scrollBy methods to ShadowView and ShadowScrollView [Issue #3944]
  • Add ShadowEventLog and ShadowProcess.setUid() [Issue #3944]
  • Add a Shadow class for MediaBrowserCompat. [Issue #3944]
  • Support ConnectivityManager#reportNetworkConnectivity [Issue #3944]
  • Add shadow for DropboxManager. [Issue #3944]
  • Add support for DisplayManager#setDisplaySaturation [Issue #3952]
  • Add scrollBy methods to ShadowView and ShadowScrollView [Issue #3952]
  • Add shadow for UsageStatsManager.queryUsageStats() and a builder for UsageStats. [Issue #3952]
  • Extend ShadowNfcAdapter to verify ndefPushMessage and emulate absence of NFC hardware [Issue #3952]
  • Improve fidelity of WifiInfo by removing shadows in favor of using real Android code. [Issue #3911]
  • Add a Shadow class for MediaControllerCompat. [Issue #3956]
  • Add ShadowNotificationManager#setNotificationPolicyAccessGranted(float) [Issue #3956]
  • Add support for isSystemUser to ShadowUserManager. [Issue #3956]
  • Adding a basic Shadow for the CaptioningManager. [Issue #3956]
  • Add layerType to ShadowView [Issue #3956]

Bug fixes

  • Implement ShadowDevicePolicyManager#setPackagesSuspended correctly. [Issue #3911]
  • Add a NoOp implementation of NfcAdapter#setOnNdefPushCompleteCallback. [Issue #3911]
  • Fix string HTML attributes in binary resources. [Issue #3911]
  • Avoid throwing in Bitmap#reconfigure for non-native backed Bitmaps. [Issue #3911]
  • Overriding getActivityIntent in ActivityTestRule has no effect [Issue #3918]
  • Improved handling of lockTaskMode that works now across activities and ActivityManager. [Issue #3924]
  • Fix NPEs when calling Surface#release and getString [Issue #3924]
  • Enhance TelephonyManager support [Issue #3944]
  • Set DataSource in ShadowMediaPlayer.create() [Issue #3944]
  • Fix signature of ShadowAccessibilityNodeInfo.setTraversalBefore()/After [Issue #3944]
  • Added a few methods to the ShadowCamera to prevent an NPE in Camera.Parameters and execute callbacks passed to takePicture [Issue #3952]
  • Improved package lost sequence number check [Issue #3956]
  • Don't modify PendingIntent extras upon sending it [Issue #2503]

Deprecations

  • Deprecate SupportFragmentTestUtil [Issue #3911]

Removals

  • Remove ShadowApplication.getApplicationContext() in favor of RuntimeEnvironment#application [Issue #3911]
  • Remove unused ShadowFrameLayout [Issue #3924]
  • Remove @implementation methods from ShadowViewGroup that are not necessary as we can just call the real implementation instead. [Issue #3924]
  • Delete shadows.MotionEventBuilder in favor of using androidx.test.core.view.MotionEventBuilder [Issue #3956]

Known Issues

Use Robolectric:

testCompile "org.robolectric:robolectric:4.0-beta-1"

Find more details here. Report issues here. Enjoy!

Sep 20, 2018
Bazel support for 3.8

@brettchabot brettchabot released this Jul 23, 2018 · 288 commits to master since this release

Assets 2

Robolectric 4.0 Alpha 3 brings support for Android 28 release, errorprone, shadow method validation and many other improvements. This is an alpha release, use with caution. APIs are likely to change before the final release of Robolectric 4.0.

Features

  • Support for the Android 28 API [Issue #3933]
  • Add errorprone/auto-refactoring support [Issue #3944]
  • Verify shadow @implementation methods against SDKs [Issue #3952]
  • Support Espresso typeText [Issue #3919]
  • Add SupportFragmentController#setupFragment() [Issue #3911]
  • Shadow get/setNotificationPolicy on NotificationManager [Issue #3911]
  • Adds a simple Shadow for JobService so classes that extend it can call jobFinished() without crashing. [Issue #3911]
  • Add createSensorEvent and sendSensorEventToListeners to ShadowSensorManager [Issue #3911]
  • Make the result of WifiScanner#startScan() configurable. [Issue #3911]
  • Add functionality for setting the unbadged application icon in ShadowPackageManager [Issue #3919]
  • Support OnAlarmListener call in ShadowAlarmManager [Issue #3919]
  • Add ParameterizedRobolectricTestRunner#parameter annotation and remove dependency on XStream [Issue #3919]
  • Support CookieManager.removeAllCookies. [Issue #3919]
  • Add overloads to PendingIntent.send [Issue #3919]
  • Support retrieving the last message sent via Messenger [Issue #3919]
  • Add implementation for getAppStandbyBuckets and setAppStandbyBuckets to ShadowUsageStatsManager [Issue #3919]
  • Adding error behavior to ShadowGeocoder. [Issue #3919]
  • Add basic GLES20 support. [Issue #3924], [Issue #3944]
  • Add support for new LocationManager API in Android P [Issue #3924]
  • Add support to ShadowPowerManager to capture rebooting. [Issue #3924]
  • Add support for Parcel.read/writeBlob [Issue #3924]
  • Improve ShadowSoundPool adding the ability to query played sounds. [Issue #3944]
  • Add method to override system properties [Issue #3944]
  • Add BluetoothDevice#getUuids/setUuids [Issue #3944]
  • Enhance support for BluetoothGatt [Issue #3944]
  • Implement the newer AudioManager request and abandon audio focus api [Issue #3944]
  • Add ShadowPackageManager#addSystemSharedLibraryName [Issue #3944]
  • Add setMode and checkOpNotThrow (hidden) APIs to ShadowAppOpsManager [Issue #3944]
  • Update ShadowDebug to allow for method tracing. [Issue #3944]
  • Add setTimeZone method to ShadowAlarmManager [Issue #3944]
  • Add ShadowVisualVoicemailSms [Issue #3944]
  • Add scrollBy methods to ShadowView and ShadowScrollView [Issue #3944]
  • Add ShadowEventLog and ShadowProcess.setUid() [Issue #3944]
  • Add a Shadow class for MediaBrowserCompat. [Issue #3944]
  • Support ConnectivityManager#reportNetworkConnectivity [Issue #3944]
  • Add shadow for DropboxManager. [Issue #3944]
  • Add support for DisplayManager#setDisplaySaturation [Issue #3952]
  • Add scrollBy methods to ShadowView and ShadowScrollView [Issue #3952]
  • Add shadow for UsageStatsManager.queryUsageStats() and a builder for UsageStats. [Issue #3952]
  • Extend ShadowNfcAdapter to verify ndefPushMessage and emulate absence of NFC hardware [Issue #3952]
  • Improve fidelity of WifiInfo by removing shadows in favor of using real Android code. [Issue #3911]
  • Add a Shadow class for MediaControllerCompat. [Issue #3956]
  • Add ShadowNotificationManager#setNotificationPolicyAccessGranted(float) [Issue #3956]
  • Add support for isSystemUser to ShadowUserManager. [Issue #3956]
  • Adding a basic Shadow for the CaptioningManager. [Issue #3956]
  • Add layerType to ShadowView [Issue #3956]

Bug fixes

  • Implement ShadowDevicePolicyManager#setPackagesSuspended correctly. [Issue #3911]
  • Add a NoOp implementation of NfcAdapter#setOnNdefPushCompleteCallback. [Issue #3911]
  • Fix string HTML attributes in binary resources. [Issue #3911]
  • Avoid throwing in Bitmap#reconfigure for non-native backed Bitmaps. [Issue #3911]
  • Overriding getActivityIntent in ActivityTestRule has no effect [Issue #3918]
  • Improved handling of lockTaskMode that works now across activities and ActivityManager. [Issue #3924]
  • Fix NPEs when calling Surface#release and getString [Issue #3924]
  • Enhance TelephonyManager support [Issue #3944]
  • Set DataSource in ShadowMediaPlayer.create() [Issue #3944]
  • Fix signature of ShadowAccessibilityNodeInfo.setTraversalBefore()/After [Issue #3944]
  • Added a few methods to the ShadowCamera to prevent an NPE in Camera.Parameters and execute callbacks passed to takePicture [Issue #3952]
  • Improved package lost sequence number check [Issue #3956]
  • Don't modify PendingIntent extras upon sending it [Issue #2503]

Deprecations

  • Deprecate SupportFragmentTestUtil [Issue #3911]

Removals

  • Remove ShadowApplication.getApplicationContext() in favor of RuntimeEnvironment#application [Issue #3911]
  • Remove unused ShadowFrameLayout [Issue #3924]
  • Remove @implementation methods from ShadowViewGroup that are not necessary as we can just call the real implementation instead. [Issue #3924]
  • Delete shadows.MotionEventBuilder in favor of using androidx.test.core.view.MotionEventBuilder [Issue #3956]

Known Issues

  • Binary resources are not yet supported for Android P.

Use Robolectric:

testCompile "org.robolectric:robolectric:4.0-alpha-3"

Find more details here. Report issues here. Enjoy!

@brettchabot brettchabot released this May 14, 2018 · 461 commits to master since this release

Assets 2

Robolectric 4.0 Alpha 2 brings support for androidx.test APIs and the Android P beta platform. This is an alpha release, use with caution. APIs are likely to change before the final release of Robolectric 4.0.

Features

  • Support the androidx test 1.1.0-alpha2 APIs, including initial support for Espresso interactions (button clicks)
  • Support for the Android P beta platform

Known Issues

  • Binary resources are not yet supported for Android P.

Use Robolectric:

testCompile "org.robolectric:robolectric:4.0-alpha-2"

Find more details here. Report issues here. Enjoy!

@xian xian released this May 9, 2018 · 507 commits to master since this release

Assets 2

Robolectric 4.0 Alpha 1 brings support for Android Jetpack Test APIs, major performance and fidelity improvements, and numerous other fixes and improvements. This is an alpha release, use with caution. APIs are likely to change before the final release of Robolectric 4.0.

Features

  • Support for androidx.test APIs for testing.
  • Support for loading resources processed using the Android build toolchain (aapt) (requires Android Gradle Plugin 3.2, or Bazel's android_local_test) [issue #3850].

Changes

  • Remove deprecated @Config properties constants, buildDir, and abiSplit [issues #3831 and #3859].
  • Correct ShadowBitmap.createdFrom fields [issue #3841].
  • Provide a way for excluding packages to acquire in the sandbox classloader [issue #3676—thanks @kageiit].

Known Issues

  • Binary resources are not yet supported for Android P.
  • The supported version of Android P is Developer Preview 2. To be updated shortly.
  • android.support.test is supported right now, androidx.test coming shortly.

Use Robolectric:

testCompile "org.robolectric:robolectric:4.0-alpha-1"

Find more details here. Report issues here. Enjoy!

Apr 24, 2018

@brettchabot brettchabot released this Mar 16, 2018 · 975 commits to master since this release

Assets 2

Robolectric 3.8 brings support for Android P, performance improvements, and numerous other fixes and improvements.

Features

  • Add support for Android P Developer Preview rev 2 [issue #3821].
  • Performance improvement: remove redundant rest of shadows before tests. [issue #3814].
  • Add ActivityController.windowFocusChanged() API.
  • NotificationManager simulation improvements [issue #3617].
  • Add shadow support for ActivityManager.getMyMemoryState [issue #3775].
  • Add isStopped() method to ShadowTextToSpeech [issue #3818].
  • Shadow DevicePolicyManager.getStorageEncryptionStatus [issue #3807].
  • Added setManifestShortcuts() and setMaxShortcutCountPerActivity() to ShadowShortcutManager [issue #3803].
  • Add shadow support for Settings#canDrawOverlays().

Deprecations

  • ShadowNetworkInfo#newInstance() and setConnectionStatus().

Bug Fixes

  • Fix ShadowMediaPlayer does not correctly handle instantiation off the UI thread. [issue #3050].
  • Allow Jacoco code coverage to work with Robolectric. [issue #3791].
  • Collapse internal whitespace down to single space character in string [issue #3791].
  • Cleanup Shadow MessageQueue/Looper and ViewRootImpl.

Misc

  • Update android O-MR1 platform to newer build [issue #3817].
  • Move JarInstrumentor to sandbox module [issue #3806].

Use Robolectric:

testCompile "org.robolectric:robolectric:3.8"

Find more details here. Report issues here. Enjoy!

@brettchabot brettchabot released this Feb 15, 2018 · 1120 commits to master since this release

Assets 2

Robolectric 3.7.1 contains two regression fixes.

Bug Fixes

  • Filter out disabled components in PackageManager query/resolve methods [#3748].
  • Fix 'PackageParser' compile errors when referencing ShadowPackageManager.addPackage [#3752].

Dependencies

  • Requires compiling against SDK 27.
  • Introduces an optional dependency on com.android.support.test:monitor:1.0.2-alpha1. If your project already depends on com.android.support.test.* , you should upgrade to 1.0.2-alpha1 to avoid potential conflicts e.g. java.lang.VerifyError: class org.robolectric.android.fakes.RoboMonitoringInstrumentation overrides final method specifyDexMakerCacheProperty.

Use Robolectric:

testCompile "org.robolectric:robolectric:3.7.1"

Find more details here. Report issues here. Enjoy!

@jongerrish jongerrish released this Feb 14, 2018 · 1120 commits to master since this release

Assets 2

Robolectric 3.7 brings simulation improvements and better shadow support as well as numerous other fixes and improvements.

This is the second of several releases in which we're replacing Robolectric's hacked-together approximations of the Android resource management code with actual code from the framework. The result should be a vastly more correct Android simulation.

Features

  • System Services
    • Initial support for FingerprintManager, KeyguardManager, SearchManager, ShortcutManager, UsbManager, RestrictionsManager, TextClassificationManager, and AutofillManager.
    • Vastly improved support for PackageManager, using much more actual Android framework code for manifest parsing.
    • Improved support for UserManager, WifiManager, TelephonyManager, and DevicePolicyManager.
  • Support for building using Bazelinstructions here.
  • System properties now more closely correspond to the Android framework values.
  • Improvements to Shadow support.
    • @Implementation methods can and should now be protected.
    • Performance improvements to shadow handling of > ~1 second per test run, big impact for the interactive use case.
    • New developer's guide for Shadow authors.
  • Beta support for ATSL's ActivityTestRule and Espresso Intents.
  • Lots of other stuff; see change list below.

Dependencies

  • Requires compiling against SDK 27.
  • Introduces an optional dependency on com.android.support.test:monitor:1.0.2-alpha1. If your project already depends on com.android.support.test.* , you should upgrade to 1.0.2-alpha1 to avoid potential conflicts e.g. java.lang.VerifyError: class org.robolectric.android.fakes.RoboMonitoringInstrumentation overrides final method specifyDexMakerCacheProperty.

Migration Notes

  • The shadow methods for Managers listed above have been switched from public to protected. Your test code may have been calling these erroneously instead of calling the Android SDK method, e.g: prefer
    PackageManager.getPackageInfo() to ShadowPackageManager.getPackageInfo(). This is easily fixed by calling the SDK method instead.
  • AndroidManifest has been removed; instead, use PackageManager APIs.

Deprecations

  • ShadowApplication.getReceiversForIntent() and hasReceiversForIntent() are deprecated; use PackageManager APIs instead.
  • ShadowUserManager.setSerlialNumberForUser() is deprecated; use addUserProfile() instead.
  • @Implementation(inheritImplementationMethods = true) is largely unnecessary and will be removed in a forthcoming release.
  • Shadow support for equals/hashcode/toString support in cases where the method exists only on a parent of the shadowed class is deprecated. Don't shadow equals() for the purposes of testing or assertions, rather only for simulation equivalency.
  • RoboLayoutInflater is deprecated; use LayoutInflater instead.
  • RoboVibrator is deprecated, functionality has moved to ShadowVibrator.

Changes

  • Support FingerprintManager [issue #3266—thanks @andreszamoraglobant].
  • ShadowMatrix does not implement map* methods [issue #3602—thanks @Kalabasa].
  • Unit test with WifiManager throws NPE [issue #3655—thanks @qsjh898].
  • Read system properties from android-all.jar!build.prop [issue #3620].
  • Change Robolectric's ShadowAccessibilityNodeInfo.equals() test to use a unique source ID [issue #3623].
  • Fix errorprone warnings [issue #3633].
  • Allow @Implementation methods to be protected instead of public [issue #3130].
  • Remove deprecated ManifestIdentifier.create() [issue #3634].
  • Default minSdkVersion should be Jelly Bean (16), not 1 [issue #3650].
  • Fix asset path searches to include all transitively reachable asset paths [issue #3652].
  • Reapply removal of deprecated ManifestFactory.create() [issue #3636].
  • Fix hash stability bug when overriding shadows using @Config [issue #3667].
  • Remove ShadowPackageManager#setQueryIntentImplicitly [issue #3672].
  • Reintroduce ATSL support as an optional dependency [issue #3679].
  • Add support to method getFromLocation on ShadowGeocoder [issue #3678—thanks @josecoelho].
  • Handle parsing float attribute values with no leading numbers [issue #3699].
  • Refactor instrumentation [issue #3654].
  • Collect perf metrics for shadow method lookup [issue #3706].
  • Refactor @Implementation method resolution [issue #3705].
  • Optimize class analysis for instrumentation [issue #3707].
  • Add RGBA_F16 to getBytesPerPixel in ShadowBitmap [issue #3687].
  • Apply sheepfood changes missed during prior syncs [issue #3718].
  • Switch Robolectric shadow tests to use android_local_test [issue #3715].
  • Fix Parcel.readByteArray() [issue #3710—thanks @cesar1000].
  • Implement ShadowMatrix mapPoints and mapVectors [issue #3609—thanks @Kalabasa].
  • Remove references to AndroidManifest from shadows [issue #3682].
  • UserManager simulation improvements [issue #3681].
  • Adds handling of permission groups to the PackageManager [issue #3680].
  • Delete ShadowActivityThreadTest [issue #3717].
  • Allow ConfigMerger to be overridden [issue #3713].
  • Add ShadowTelephonyManager.setIsSmsCapable [issue #3702].
  • Add support for FingerprintManager [issue #3696].
  • Test cleanups [issue #3695].
  • Add missing methods for testing ConnectivityManager.OnNetworkActiveLi… [issue #3694].
  • Fix Resource mapping tests [issue #3691].
  • Ignore multidex for RoboInstrumentation and code cleanup [issue #3690].
  • Add android.net.INetworkPolicyManager to ServiceManager [issue #3689].
  • Fix InstrumentationRegistryTest when running on device [issue #3686].
  • Re-introduce ActivityTestRule support [issue #3685].
  • Prepare Robolectric's test to run with AGP [issue #3683].
  • KeyguardManager simulation improvements [issue #3644].
  • UserManager simulation enhancements [issue #3643].
  • Add support for UserManager.getApplicationRestrictions() [issue #3637].
  • DevicePolicyManager simulation enhancements [issue #3675].
  • Remove check for min JDK version, Robolectric requires Java 8 anyway [issue #3669].
  • Properly set activityInfo.exported and permission and add ShadowPackageManager.getIntentFiltersForXXX APIs [issue #3666].
  • UserManager simulation enhancements [issue #3662].
  • RestrictionsMananger support getManifestRestrictions() [issue #3660].
  • KeyguardManager simulation improvements [issue #3658].
  • Add support for RestrictionsManager [issue #3656].
  • Switch ProxyMaker to use reflection to run on ART API < 26 [issue #3649].
  • UserManager simulation enhancements [issue #3648].
  • Remove obsolete ShadowsAdapter APIs [issue #3627].
  • Fix imports [issue #3625].
  • Remove @Deprecated TestLifeCycle.createApplication() [issue #3624].
  • Remove obsolete references to Robolectric.getShadowsAdapter() [issue #3622].
  • Fix infinite loop with styles [issue #3616—thanks @nll].
  • KeyguardManager's isKeyguardSecure() is API 16 [issue #3631].
  • Re-work resetter code to simplify [issue #3629].
  • Remove RuntimeEnvironment.getAppManifest [issue #3628].
  • Cache setup database in SQLiteDatabaseTest [issue #3444].
  • Optimize InstrumentingClassLoader.getCommonSuperClass() [issue #3726].
  • Refactor instrumentation even more [issue #3730].
  • Updating string resources parsing [issue #3177—thanks @pivotal-james-zcheng].
  • Xml resource string escaping [issue #3671—thanks @menny].
  • Handle receiver class names with no leading '.' [issue #3740].
  • Move WORKSPACE file and fix path [issue #3735—thanks @dkelmer].
  • Add dependencies for bazel projects using Robolectric [issue #3731—thanks @dkelmer].
  • Implement support for O system services [issue #3729].
  • WifiManager simulation enhancements [issue #3727].
  • Make some @Implementation methods protected [issue #3724].
  • Add basic shadow tro prevent NPE when dereferencing [issue #3739].
  • Add test case for default shared preferences [issue #3612—thanks @roostertech].
  • Stub out restore() method in ShadowCanvas [issue #3521—thanks @cesar1000].
  • Support ATSL Intents verification API on Robolectric [issue #3728].
  • Replace RobolayoutInflator with PhoneLayoutInflator as per framework [issue #3741].
  • Clean up new APIs in 3.7 [issue #3714].
  • Switch Vibrator from fake to Shadow [issue #3742].
  • Implement equals() in ShadowPorterDuffColorFilter [issue #3522—thanks @cesar1000].
  • Add utility to ShadowToast to check whether a toast was cancelled [issue #3711—thanks @cesar1000].
  • SharedPreferences will not persist edits across getSharedPreferences calls [issue #3510—thanks @setheclark].
  • SharedPreferences' commit() hangs if executed after apply() on Android O [issue #3641—thanks @kzaikin].
  • BadParcelableException when unmarshalling Parcelable extending class [issue #2398—thanks @menny].
  • Problem of WARNINGs [issue #3646—thanks @XinyueZ].

Use Robolectric:

testCompile "org.robolectric:robolectric:3.7"

Find more details here. Report issues here. Enjoy!