Releases: robolectric/robolectric
Robolectric 4.0.1
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!
Robolectric 4.0
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.
With the major version number bump to 4.0, we're making changes to some public APIs, detailed below. Check out the migration notes and use the new automated migration tool to help convert your existing tests to be compatible with Robolectric 4.0.
API Changes
- Most
@Implementation
methods in shadow classes are nowprotected
instead ofpublic
. Tests should always prefer to call SDK methods directly on Android classes rather than on their shadows [issue #4007]. RuntimeEnvironment.application
has been deprecated, useandroidx.test.core.app.ApplicationProvider.getApplicationContext()
instead.AutoCloseable
is now supported. In earlier versions of Robolectric, try-with-resources blocks would fail to callclose()
on the resource.- Bumped Android P to build 4913185.
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, but is now deprecated.
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 stateBuild.getSerial()
CameraManager
andCameraCharacteristics
Camera.Parameters
preview sizesCarrierConfigManager.getConfigForSubId()
ConnectivityManager
support forNetworkCapabilities
,requestNetwork()
.ContentResolver.openOutputStream()
, 'getSyncAdapterTypes()'Context.bindServiceAsUser()
DevicePolicyManager.setUserProvisioningState()
EuiccManager
FontFamily
- Improvements to
AccessibilityNodeInfo
NotificationManager
support forAutomaticZenRule
sPackageManager.checkPermission()
checksPackageInfo.requestedPermissionsFlags
to determine if a permission is granted.Path
,PathMeasure
, andPathParser
SensorManager
Service.stopSelfResult()
ShadowSensor.newInstance()
Sms
SoundPool
now records more details whenplay()
is called.StorageManager
test API for adding volumes.SubscriptionManager.getActiveSubscriptionInfoForSimSlotIndex()
,getActiveSubscriptionInfoCount()
etc., 'getDefaultSubscriptionId()'SystemClock.elapsedRealtimeNanos()
andcurrentNetworkTimeMillis()
TelecomManager.silenceRinger()
TelephonyManager.getSubscriberId()
,getSimSerialNumber()
, 'getVoiceNetworkType()'TextToSpeech
Tile
andTileService
minimal implementationTimeZoneFinder
UsbManager
UserManager
now supports multiple users.UserStatsManager
test API:ShadowUserStatsManager.simulateTimeChange()
; useEventBuilder
can be used to return arbitrary eventsVMRuntime.is64Bit()
,ShadowVMRuntime.setIs64Bit()
,ShadowBuild.setSupported64BitAbis()
WebStorage
WebView.saveState()
andrestoreState()
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 createMediaItem
s and get all createdMediaItem
s with their parent-child relationships [thanks Jehron Petty and Noah Luddy!].getRoot()
,getItem()
,subscribe()
, andsearch()
can only be called successfully afterShadowMediaBroswserCompat.connect()
is called.- The default root id is
root_id
. This is what will be returned bygetRoot()
by default. The root id can be changed withsetRootId()
. Note that if the root is created withcreateMediaItem()
,setRootId()
must also be called with the samemediaId
. - There is no
getSessionToken()
method inShadowMediaBrowserCompat
. Follow issue #3962 for updates.
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]
- Added support for
androidx.test
'sActivityScenario
API. - Fixes for
ShadowBitmap.(set|is)Premultiplied()
andShadowWebView.copyBackForwardList()
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]
- Fix
ActivityScenario
support [Issue #4022] View.post()
andpostDelayed()
. now more properly returntrue
, which fixes a bug that sometimes caused duplicate tap events to be delivered.
Deprecations
- Deprecate SupportFragmentTestUtil [Issue #3911]
ShadowApplication.getInstance()
ShadowLooper.getShadowMainLooper()
Config(packageName)
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]
- `S...
Robolectric 4.0 beta 3
NOTE: Robolectric 4.0-beta-3 is a outdated release candidate; please use 4.0 instead.
Robolectric 4.0 beta 2
NOTE: Robolectric 4.0-beta-2 is a outdated release candidate; please use 4.0 instead.
Robolectric 4.0 Beta 1
NOTE: Robolectric 4.0-beta-1 is a outdated release candidate; please use 4.0 instead.
Robolectric 4.0 Alpha 3
NOTE: Robolectric 4.0-alpha-3 is a outdated release candidate; please use 4.0 instead.
Robolectric 4.0 alpha 2
NOTE: Robolectric 4.0-alpha-2 is a outdated release candidate; please use 4.0 instead.
Robolectric 4.0 alpha 1
NOTE: Robolectric 4.0-alpha-2 is a outdated release candidate; please use 4.0 instead.
Robolectric 3.8
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 toShadowTextToSpeech
[issue #3818]. - Shadow DevicePolicyManager.getStorageEncryptionStatus [issue #3807].
- Added
setManifestShortcuts()
andsetMaxShortcutCountPerActivity()
toShadowShortcutManager
[issue #3803]. - Add shadow support for
Settings#canDrawOverlays()
.
Deprecations
ShadowNetworkInfo#newInstance()
andsetConnectionStatus()
.
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
andViewRootImpl
.
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!
Robolectric 3.7.1
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 oncom.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!