Skip to content

Releases: robolectric/robolectric

Robolectric 4.2

14 Feb 21:02
Compare
Choose a tag to compare

This release introduces a new extension mechanism for Robolectric, fixes a major performance regression in 4.x, and includes numerous SDK support improvements and bug fixes.

Features

  • Robolectric 4.2 introduces a new plugin system, replacing the previous ad-hoc customization mechanisms (subclassing RobolectricTestRunner, providing system properties, etc.). The old mechanisms are deprecated and will eventually be removed; let us know if there are missing extension points you need. See org.robolectric.pluginapi for more details [issue #4362].
  • Fixed a significant performance regression in 4.x. Thanks @cesar1000! [issues #4142, #4585].
  • For developers of custom shadows, Robolectric 4.2 has a new typesafe and more performant way to access fields and methods on @RealObjects using the Reflector API [issues #4361, #4315, #4351, #4456]

Android SDK support and Test API changes

  • Activities must now be explicitly declared in a manifest (as is the case for normal Android). See #4736 for more context.
  • PackageManager
    • PackageManager is moving to returning defensive immutable copies of its internal data (as on a real device). A series of new testing APIs have been added to modify the package under test; see PackageManager.addOrUpdateActivity() and removeActivity(), plus Service, ContentProvider, and BroadcastReceiver equivalents [issue #4489].
    • Implement PackageManager.isSafeMode() [issue #4526].
  • ShadowDisplayManager.getSaturationLevel() is now an instance method [issue #4522].
  • Telephony
    • Add slotId based getImei() and getMeid() to TelephonyManager [issue #4521].
    • Add the ability to prevent certain networks from being updated in tests [issue #4515].
    • Implement TelephonyManager.getListenersForFlags in tests [issue #4469].
    • Implement TelephonyManager.getVisualVoicemailPackageName() [issue #4444].
  • Bluetooth
    • Test APIs for BluetoothSocket and BluetoothServerSocket connections [issue #4510].
    • Implement BluetoothLeAdvertiser [issues #4478 and #4454].
    • Implement BluetoothHeadset.getConnectedDevices(), getConnectionState(), and sendVendorSpecificResultCode(), with test APIs [issue #4442].
    • Add ability to send BluetoothGattCallback connection state change updates [issue #4584].
  • Implement ActivityManager#getCurrentUser() [issue #4483].
  • UserManager
    • Implement UserManager.getUserSerialNumber() [issue #4501].
    • UserManager#addUser returns a UserHandle to the user it creates [issue #4449].
    • Add isRestrictedProfile() and setIsRestrictedProfile() [issue #4554].
  • Implement Context.sendBroadcastAsUser [issue #4486].
  • Implement WindowManagerImpl#removeViewImmediate(View) [issue #4447].
  • Implement SensorManager.registerListener(): [issue #4446].
  • Implement NetworkScoreManager.disableScoring() and isScoringEnabled() to [issue #4436].
  • DevicePolicyManager now enforces password restrictions [issues #4532, #4545, and #4539].
  • Implement UiModeManager [issue #4548].
  • Implement AccessibilityManager#addAccessibilityStateChangeListener(AccessibilityStateChangeListener, Handler) [issue #4448].
  • Implement ParcelFileDescriptor.createReliablePipe method [issue #4562].
  • Move intent filters to their own lists and out of the Package [issue #4488].
  • Implement WifiRttManager and RangingResult [issue #4561].
  • Add test API to toggle a Sensor wake-up mode [issue #4558].
  • Add PowerManager.WakeLock getTimesHeld() test API to count number of times the wakelock was held [issue #4551].
  • Adds basic MediaCodec and MediaMuxer shadows to robolectric. The MediaCodec shadow implements basic passthrough asynchronous encoding, and the MediaMuxer shadow muxes input bytes directly to the file without modification [issue #4550].
  • Update to ShadowDevicePolicyManager to allow uses-policy granting [issue #4546].
  • Modify ShadowParcel to throw an Error instead of RuntimeException to discourage [issue #4528].
  • Don't autocreate activities in LocalActivityInvoker anymore [issue #4582].
  • Don't automatically generate default ActivityInfo whenever asked [issue #4580].
  • Implements WebView.removeJavascriptInterface [issue #4575].
  • Update to ShadowDevicePolicyManager to set storage encryption [issue #4563].

Configuration

  • There are some small changes to the way Android SDK jars are located; see (LegacyDependencyResolver javadoc)[http://robolectric.org/javadoc/4.2/org/robolectric/plugins/LegacyDependencyResolver.html] for details [issue #4599].

Bug Fixes

  • The android system context is no longer a parent of the application context [issue #4481].
  • Fix LocalActivityInvoker.recreateActivity. Before this change, it called Activity.onRetainNonConfigurationInstance() directly to obtain nonConfigInstance for the activity. This should've called indirectly from Activity.retainNonConfigurationInstances(). retainNonConfigurationInstances() also creates nonConfigInstances for fragments to prepare for the host activity recreation [issue #4511].
  • Fix timeout in FontsContract.getFontSync() caused because Context.canLoadUnsafeResources() now returns false since the context isn't a system context [issue #4517].
  • Fix handling of persisted preferred activities [issue #4480].
  • Fix processName setting and add few more reasonable defaults when installing new package [issue #4465].
  • Add permission check to LocationManager.setLocationEnabledForUser [issue #4500].
  • No longer reset the data position after unmarshalling a ShadowParcel [issue #4468].
  • Fix NPE Robolectric when a failure occurs before shadows are set up [issue #4467].
  • Set AppBindData#processName consistently with ApplicationInfo#processName [issue #4537].
  • Throw NameNotFoundException from Context.createPackageContext for non-existing packages [issue #4527].
  • Synchronize access to ShadowPendingIntent and ShadowUsageStatsManager fields [issue #4520].
  • Fix Activity#isChangingConfigurations() returning false during the recreation [issue #4540].
  • Fix equality in ShadowNetwork [issue #4464].

Deprecations and Removals

  • FsFile et al. have been removed in favor of java.nio.file.Path [issue #4265].
  • ShadowPackageManager.addResolveInfoForIntent is deprecated; add explicit activity declarations in your manifest, or use ShadowPackageManager.addOrUpdateActivity(ActivityInfo) [issue #4489].
  • Deprecate Robolectric#setupActivity in favor of ActivityScenario [issue #4564].

Internal Changes

  • Tests are now run on a dedicated thread for each SDK [issue #4559].
  • Resolve AARs like the android plugins do (kind of) [issue #4279].
  • Reflector objects should unwrap invocation exceptions [issue #4361].
  • Fast private method invocation [issue #4315].
  • Add support for static methods and fields to Reflector [issue #4351].
  • Fix Reflector class definition in Java 11 [issue #4456].
  • Support Java 9 [issue #4400].
  • Robolectric now builds successfully on Windows, though a few tests still fail [issue #4293].
  • Extensible configuration system [issue #4519].
  • Switch circleci to API 28 image. Fix SDK install license fail [issue #4541].
  • Changes to support Java 9 [issue #4452].
  • TypedArray doesn't need a shadow in binary mode [issue #4470].
  • Extract Sdk from SdkConfig [issue #4394].
  • Clean up SdkProvider interface [issue #4513].
  • Move PerfStatsReporter to pluginapi [issue #4471].
  • PerfStatsCollector retains min and max timing info for events [issue #4552].
  • Remove DefaultConfigMerger [issue #4549].

Known Issues

  • Activities must now be explicitly declared in a manifest (as is the case for normal Android); however, Android Gradle Plugin doesn't currently merge a test manifest. See #4736 for more context and #4727 for a workaround.
  • Robolectric 4.2 doesn't work on Windows in some cases [issue #4603 et al.].
  • Android Gradle Plugin 3.2.1 and 3.3 report the following warning, which may be safely ignored: WARNING: The option setting 'android.enableUnitTestBinaryResources=true' is experimental and unsupported.. Android Gradle Plugin 3.4 will resolve this issue.
  • Android Gradle Plugin 3.2.1 does not work on Windows; use 3.3 instead [issue #3955].

Compatibility

  • Android Studio/Android Gradle Plugin 3.3 or 3.4 Beta
  • Android SDK 28 (includes support for testing against SDKs from 16 on)

Use Robolectric:

testCompile "org.robolectric:robolectric:4.2"

Find more details here. Report issues here. Enjoy!

Robolectric 4.2 Beta 1

07 Feb 00:43
Compare
Choose a tag to compare
Pre-release

NOTE: Robolectric 4.2-beta-1 is an outdated beta release; please use the latest release of 4.2 instead.

Robolectric 4.2 Alpha 2

01 Feb 21:19
Compare
Choose a tag to compare
Pre-release

NOTE: Robolectric 4.2-alpha-2 is an outdated alpha release; please use the latest release of 4.2 instead.

Robolectric 4.2 Alpha 1

28 Jan 19:47
Compare
Choose a tag to compare
Pre-release

NOTE: Robolectric 4.2-alpha-1 is an outdated alpha; please use the latest release of 4.2 instead.

Robolectric 4.1

13 Dec 01:10
Compare
Choose a tag to compare

Robolectric 4.1 has improved support for a number of androidx.test APIs, and new and improved support and testing APIs for scores of Android classes. Robolectric also now works on Windows again, and has a bunch of other awesome bug fixes.

Features

  • Support ActivityScenario and Espresso in Robolectric paused looper mode [issues #4084 and #4157].
  • Add support for Espresso Intents intending() stubbing functionality [issue #4150].
  • Add ShadowAccessibilityButtonController.
  • Add ShadowDevicePolicyManager.isDeviceManaged().
  • Support androidx.test.core.app.ActivityScenario#getActivityResult.
  • Support androidx.test ActivityScenario#getResult.
  • Add ShadowActivity#getLastRequestedPermission.
  • Support ActivityManager#switchUser.
  • Add SupportFragmentController#saveInstanceState.
  • Add ShadowService#getStopSelfId and getStopSelfResultId.
  • Enhance support for `TextToSpeech#speak.
  • Support PackageManager#getPackagesForUid.
  • Support PackageManager#getResourcesForActivity.
  • Limited support for PackageManager#isInstantApp [issue #3991].
  • Properly implement SharedMemory#map.
  • Add ShadowTrafficStats#tagDatagramSocket.
  • Add VpnService support.
  • Add ShadowConnectivityManager#getLinkProperties.
  • Support setting additional StorageVolume attributes via the builder.
  • Add ShadowServiceManager#setServiceAvailability.
  • Add ability to grant/deny permissions for specific process id and user id.
  • Support Bitmap#eraseColor.
  • Support Bitmap.createBitmap(Picture).
  • Support GLES20 glGenFramebuffers.
  • Support Matrix#setRectToRect.
  • Add ShadowStatusBarManager#getDisableFlags and getDisable2Flags.
  • Support AppsOpManager#noteProxOpNoThrow.
  • Add ShadowWebView#setCurrentWebViewPackage.
  • Add support for checking component enabled status.
  • Add WifiManager#getActiveLockCount.
  • Support BluetoothSocket.
  • Support CaptioningManager listeners.
  • Add shadow for performAccessibilityShortcut.
  • Add Trace support.
  • Remove ability to shadow Object.equals/hashCode/toString on subclasses [issue #3692].
  • Remove deprecated @Implements(inheritImplementationMethods) [issue #3909].
  • Feature request: add mapRadius of ShadowMatrix [issue #4055—thanks @crupest].
  • Add mapRadius for ShadowMatrix [issue #4063—thanks @crupest].
  • Make enabled and other flags in the manifest visible in the Component [issue #4103].
  • Prefetch android all m2 [issue #4237].

Bug Fixes

  • Fix parsing of Windows paths [issue #4287].
  • Obtain file lock before downloading android-all from maven - prevents multiple continuous builds corrupting shared android-all jars [issue #3659].
  • Fix BCP47 language tag generation in ShadowAssetManager.
  • Remove custom managed instances of AppWidgetManager, allow Android to manage instance singletons now.
  • Avoid deadlocks in ClassValueMap exposed with newer versions of cglib with mockito.
  • Fix ApplicationInfo.sourceDir for LOLLIPOP+.
  • Support androidx.test.rules.GrantPermissionRule [issue #4133].
  • Fix concurrent android-all download corruption [issue #4237].
  • PackageManager compatibility fixes:
    • Return defensive copies of ResolveInfo and ApplicationInfo objects.
    • Ensure created components are enabled.
    • Add `FLAG_INSTALLED. by default when adding packages, and add new APIs to add packages without adding default flags.
    • Properly load icons/logos for application components.
  • Fix ResourcesCompat.getFont() on API > 26.
  • Fix WebViewDatabase support.
  • Reset ShadowSubscriptionManager state between tests.
  • Support special characters in espresso typeText [issue #4129].
  • Make Bitmap.compress actually write the image to the stream.
  • Support androidx.test GrantPermissionRule [issue #4133].
  • Make SupportFragmentController call on postCreate at correct point.
  • Fix parsing negative hex numbers in resources.
  • Add an auth intent to the getAuthToken callback bundle if no token is available.
  • Only load SoundPool callbacks for known sounds.
  • Set ServiceInfo.processName from ApplicationInfo.processName [issue #4099].
  • Use ASM 7.0 to support class bytecode version 12 and Java 10+. [issue #4085].
  • Fix iteration over integer keys in a hashmap that caused some resource types to be skipped. [issue #4082].
  • Fix ShadowWindowManagerImpl#getViews() for post-Lollipop.
  • ShadowBitmapFactory.decodeByteArray() always returns a 100x100 Bitmap [issue #4028—thanks @tryal-leaf].
  • Method getLocales in android.content.res.Configuration not mocked [issue #4015—thanks @nikoskyr].
  • Method getLocales in android.content.res.Configuration not mocked [issue #4073—thanks @ScottPierce].
  • java.lang.RuntimeException: Failed to extractAlpha on Bitmap [issue #2795—thanks @zhengxiaopeng].
  • GrantPermissionRule rule does not work on AndroidJUnit4 tests [issue #4133—thanks @goblinr].
  • Fix Canvas NoClassDefFound EGLContext error [issue #4146—thanks @jaredsburrows].
  • ShadowKeyCharacterMap doesn't handle '@' or '-' characters [issue #4129—thanks @aisanu].
  • Espresso calls hang when looper is paused [issue #4084].
  • ActivityScenario.launch fails with paused looper [issue #4157].
  • android-all jar download race (tests failing when maxParallelForks > 1) [issue #2346—thanks @NicoloParolini].
  • Espresso Intents onActivityResult() not invoked when intending() matches a component [issue #4150].
  • Unhelpful error message (java.lang.IllegalStateException: this method should only be called by Robolectric) [issue #4235—thanks @neworld].
  • 4.1-beta-2 Bitmap.eraseColor NPE [issue #4289—thanks @NickButcher1].
  • Fix confusing error message when application.onCreate fails [issue #4286].
  • Oops, fix wrong string splits [issue #4156].
  • Fix ApplicationInfo.sourceDir for LOLLIPOP+ [issue #4270].
  • Synchronize maven downloads of android-all [issue #4241].
  • Fix enum value parsing to allow negative values [for legacy resources] [issue #4112—thanks @cesar1000].

Deprecations and Removals

  • Rename addPackage to installPackage in ShadowPackageManager and deprecate.
  • Deprecate ShadowApplication.getAppWidgetManager().
  • Remove ShadowHandler [issue #4245].
  • Make ShadowSharedMemory implementation methods protected.
  • Rename ShadowPackageManager#getPackageInfoForTesting to getInternalMutablePackageInfo.
  • Deprecate ShadowResolveInfo#setLabel.
  • Remove RoboLayoutInflater and ShadowApplication.getLayoutInflater.

Known Issues

  • Android Gradle Plugin 3.2.1 and 3.3 report the following warning, which may be safely ignored: WARNING: The option setting 'android.enableUnitTestBinaryResources=true' is experimental and unsupported.. Android Gradle Plugin 3.4 will resolve this issue.
  • Android Gradle Plugin 3.2.1 does not work on Windows; use 3.3 instead [issue #3955].

Robolectric 4.1 beta 2

07 Dec 20:04
Compare
Choose a tag to compare
Pre-release

NOTE: Robolectric 4.1-beta-2 is a outdated preview release; please use 4.1 instead.

Robolectric 4.1 beta 1

07 Dec 20:03
Compare
Choose a tag to compare
Pre-release

NOTE: Robolectric 4.1-beta-1 is a outdated preview release; please use 4.1-beta-2 instead.

Robolectric 4.1 alpha 1

07 Dec 20:03
Compare
Choose a tag to compare
Pre-release

NOTE: Robolectric 4.1-alpha-1 is a outdated preview release; please use 4.1 instead.

Robolectric 4.0.2

10 Nov 01:35
Compare
Choose a tag to compare

Robolectric 4.0.2 fixes several bugs in 4.0:

Bug Fixes

  • Resources.getXml() fails with Android 9/aapt2/Studio 3.2.1 (android.content.res.Resources$NotFoundException: Resource ID #0x7f090005) resources [issue #4082].
  • Fake ServiceInfo doesn't contain processName, causing LeakCanary failure [issue #4090].
  • Java 10+ failure/java.lang.NoClassDefFoundError: android/text/TextUtils [issue #4085].
  • Robolectric crashes when loading font from Resources.getFont or ResourceCompat.getFont [issue #3590].
  • Test leakage — ShadowSmsManager is missing a resetter for static state [issue #3811].
  • java.lang.IllegalStateException - android.graphics.Canvas.__constructor__ [issue #4072].

Known Issues

  • Robolectric 4 does not work on Windows [issue #3955].
  • Android Gradle Plugin may report the following warning, which may be safely ignored: WARNING: The option setting 'android.enableUnitTestBinaryResources=true' is experimental and unsupported.. Android Gradle Plugin 3.3 will resolve this issue.

Use Robolectric:

testCompile "org.robolectric:robolectric:4.0.2"

Getting Started | Migrating | Report Issues. Enjoy!

Robolectric 4.0.1

31 Oct 21:09
Compare
Choose a tag to compare

Robolectric 4.0.1 fixes several bugs in 4.0:

Bug Fixes

  • NPE in PackageParser in binary resources mode [issue #4026].
  • Activity.getLifecycle().getCurrentState()==CREATED although activity is resumed [issue #4038].
  • 4.0 migration tool not working [issue #4052].

Known Issues

  • Robolectric 4 does not work on Windows [issue #3955].
  • Android Gradle Plugin may report the following warning, which may be safely ignored: WARNING: The option setting 'android.enableUnitTestBinaryResources=true' is experimental and unsupported.

Use Robolectric:

testCompile "org.robolectric:robolectric:4.0.1"

Getting Started | Migrating | Report Issues. Enjoy!