Releases: robolectric/robolectric
Robolectric 3.7
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
, andAutofillManager
. - Vastly improved support for
PackageManager
, using much more actual Android framework code for manifest parsing. - Improved support for
UserManager
,WifiManager
,TelephonyManager
, andDevicePolicyManager
.
- Initial support for
- Support for building using Bazel — instructions 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 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
.
Migration Notes
- The shadow methods for Managers listed above have been switched from
public
toprotected
. Your test code may have been calling these erroneously instead of calling the Android SDK method, e.g: prefer
PackageManager.getPackageInfo()
toShadowPackageManager.getPackageInfo()
. This is easily fixed by calling the SDK method instead. AndroidManifest
has been removed; instead, usePackageManager
APIs.
Deprecations
ShadowApplication.getReceiversForIntent()
andhasReceiversForIntent()
are deprecated; usePackageManager
APIs instead.ShadowUserManager.setSerlialNumberForUser()
is deprecated; useaddUserProfile()
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 shadowequals()
for the purposes of testing or assertions, rather only for simulation equivalency. RoboLayoutInflater
is deprecated; useLayoutInflater
instead.RoboVibrator
is deprecated, functionality has moved toShadowVibrator
.
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 sourceID
[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
onShadowGeocoder
[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
togetBytesPerPixel
inShadowBitmap
[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
andmapVectors
[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
toServiceManager
[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 addShadowPackageManager.getIntentFiltersForXXX
APIs [issue #3666]. UserManager
simulation enhancements [issue #3662].RestrictionsMananger
supportgetManifestRestrictions()
[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
'sisKeyguardSecure()
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
withPhoneLayoutInflator
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 acrossgetSharedPreferences
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!
Robolectric 3.6.1
Robolectric 3.6.1 fixes a couple small issues in 3.6.
Changes
- Reverted support for
android.support.test
'sInstrumentationRegistry
andActivityTestRule
for now, didn't work with Android Gradle Plugin 2.x [issue #3614]. - Reverted fix for XML references containing whitespace [issue #3198] for now, previous fix caused other problems.
Use Robolectric:
testCompile "org.robolectric:robolectric:3.6.1"
Find more details here. Report issues here. Enjoy!
Robolectric 3.6
Robolectric 3.6 provides enhanced device configuration, fixes lots of idiosyncrasies in how resources were picked based on device configuration, and includes numerous other fixes and improvements.
This is the first 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
- New device configuration APIs [issue #3559]:
- Qualifiers specified using
@Config(qualifiers="...")
are used to configure the virtual device's simulated locale, display, and hardware for the test. Display
andDisplayMetrics
now match the device's configuration.- On Jelly Bean MR1 and up, additional displays can be simulated using
ShadowDeviceManager#addDisplay()
et al. - Orientation and other configuration changes are easy to simulate and test.
- See the page on Device Configuration for lots more details.
- Qualifiers specified using
- New APIs for controlling
Build
constants andActivityManager.isLowRamDevice
[issue #3576]. - Support for
android.support.test
'sInstrumentationRegistry
andActivityTestRule
[issue #3568 and #3578]. - Bumped API 27 to released Android O 8.1 [issue #3599].
- Performance statistics collection, within plugin-able reporting mechanism [issue #3548].
- Implement 'WifiManager.setWifIInfo()' [issue #3569].
- Added support for fragment arguments in FragmentController [issue #3498].
- Add multi SIM support to
SmsManager
[issue #3561]. - Support for
ConnectivityManager
to bind networks [issue #3539]. - Implemented
ContextImpl.getSystemService(Context.CAPTIONING_SERVICE)
[issue #3527]. - Add support for
PackageManager.queryIntentServicesAsUser()
[issue #3597]. - Add time formatting support for a few locales in
ICU
[issue #3553]. - Added initial support for
AppOpsManager
andCaptioningManager
[issues #3494 and #3527]. - Implemented
context.startForegroundService()
[issue #3517].
Fidelity Improvements
- Robolectric now uses the same logic as a real Android device for selecting resources [issue #3504]:
- Qualifiers are now applied in the order specified by Android (see https://developer.android.com/guide/topics/resources/providing-resources.html#table2).
anydpi
andnodpi
may no longer be specified as@Config(qualifiers)
. SDKs which are able to render vector drawables will matchanydpi
drawables.- The default display is now 320dp x 470dp, mdpi.
- See the page on Device Configuration for lots more details.
- Attribute types are now parsed in order specified by Android [issue #3565].
ContentObserver
s now respectnotifyForDescendents
[issue #3544].AssetManager.open()
andlist()
now include assets from libraries [issue #3605].- Added support for
AlarmClockInfo
toAlarmManager
[issue #3483]. PackageManager
now handles theMATCH_DISABLED_COMPONENTS
flag [issue #3499].- Improved fidelity of how activities are notified of configuration changes [issue #3581 and #3591].
Bug Fixes
Log.getLogsForTag()
returns empty list instead ofnull
if no logs with that tag are present [issue #3550].- Tests can now be executed from any parent directory [issue #3598].
- Improved
ActivityController
lifecycle handling [issue #3591]. - Fix 'Settings.set24HourMode()` [issue #3525].
AccountManageFuture.isDone()
no longer returns true on failure [issue #3603].- Avoid NPE in
AccessibilityNodeInfo
child comparing children [issues #3589 and #3579]. - Avoid NPE in
PackageManager.getResolveInfo()
[issue #3513]. - Improved fidelity of
PendingIntent
[issue #3465]. - Fixed mipmap resource reference resolution [issue #3495].
- Fixed detection of color resource types [issue #3512].
- Whitespace in style XML files no longer causes Robolectric to hang [#3475].
Deprecations
TestLifecycle.createApplication()
[issue #3555].ShadowPackageManager.setQueryIntentImplicitly()
[issue #3584].ShadowsAdapter
and Robolectric.getShadowsAdapter()`: access shadows directly instead.- Most methods in
Qualifiers
: use@Config(qualifiers)
and related Android platform APIs instead. - Methods to directly configure a
Display
: eg.ShadowApplication.setDefaultDisplay()
,ShadowDisplay.setDisplayId()
: use@Config(qualifiers)
orRuntimeEnvironment.setQualifiers()
instead.
Misc
Migration Notes:
- Calculations using display size are likely to be affected because display metrics are now correctly configured, instead of being hard-coded to 480x800.
- More here.
Use Robolectric:
testCompile "org.robolectric:robolectric:3.6"
Find more details here. Report issues here. Enjoy!
Robolectric 3.6 alpha 1
NOTE: Robolectric 3.6-alpha-1 is a outdated release candidate; please use 3.6 instead.
Robolectric 3.5.1
Robolectric 3.5.1 provides support for Android O_MR1 8.1 beta and two regression fixes.
Features:
- Support for Android O_MR1 8.1 build 4402310 [issue #3481].
Bug Fixes:
- Reverts upgrade of bounceycastle which caused SSL handshake failures on some machines. A workaround for people whose builds were fixed by the upgrade is here [issue #3481].
- Fixed a bug for Buck users that caused an
IllegalStateException
[issue #3478].
Use Robolectric:
testCompile "org.robolectric:robolectric:3.5.1"
Find more details here. Report issues here. Enjoy!
Robolectric 3.5
Robolectric 3.5 provides support for Android O 8.0.0_r4 and includes numerous fixes and improvements.
Features:
- Support for Android O 8.0.0_r4 [issue #3439].
- Added shadows for
DevicePolicyManager
[issue #3325] andUsbManager
[issue #3420].
Fidelity Improvements
- Exceptions thrown during
Filterable
filtering are now correctly caught [issue #3331]. - Fixed a bug involving
AlarmManager
andPendingIntent
s [issue #3332]. WebView
handles history more consistently [issue #3347].- Added attributes and intent filters to
BroadcastReceiverData
andServiceData
from the manifest [issue #3361]. - Implemented
ApplicationPackageManager.getPackageUid()
[issue #3370]. - Implemented
ContentResolver.getPersistedUriPermissions()
[issue #3400]. - Implemented
PowerManager.isIgnoringBatteryOptimizations()
[issue #3399]. - Implemented
KeyguardManager#isKeyguardLocked()
[issue #3401]. - Implemented
UserManager.getSerialNumberForUser()
[issue #3406]. - Implemented
NotificationManager.deleteNotificationChannelGroup()
[issue #3334] andcreateNotificationChannels()
[issue #3340]. - More realistic values now provided for
ApplicationInfo.uid
andProcess.myUid()
[issue #3440]. - Implemented
TextUtils.ellipsize()
[issue #3442]. - Improved support for
KeyguardManager
on O [issue #3454]. - Updated bounceycastle to latest (1.58) [issue #3458].
Activity.finishAffinity()
correctly causes an activity to be marked finished [issue #3460].
Bug Fixes:
- Fixes a bug that could cause deadlocks when using
AsyncTask
[issue #3321]. - Fixed a bug that caused exceptions thrown during filtering to be incorrectly thrown [issue #3331].
- ShadowAlarmManager bug fix: PendingIntent equals check now includes requestCode type check [issue #3332].
- Separated postFrameCallback delay control from postCallback. [issue #3335].
- Disable animation during DrawerLayout.openDrawer/closeDrawer [issue #3336].
- Fixed an issue that caused missing resources to throw incorrect exceptions [issues #3312 and #3283].
AccessibilityManager
now retains state correctly [issue #3372].- Fonts in the
res
directory no longer cause an exception [issue #3398]. - Improved support for Buck projects with many library dependencies [issue #3429].
- Improved support for Java 9 [issue #3432].
Deprecations:
- Deprecated
ManifestFactory.create()
,RuntimeEnvironment.getAppManifest()
, andShadowApplication.getAppManifest()
[issue #3447].AndroidManifest
itself will be deprecated soon; usePackageManager
instead. - Deprecated
WebView.setCanGoBack()
. - Deprecated
org.robolectric.util.SimpleFuture
[issue #3321].
Misc:
- Shadow artifacts names are once again correctly prefixed with 'shadows-', so e.g.
shadows-framework
, etc. Sorry for the thrash on this. - Removed support for obsolete Maps API v1 [issue #3305].
- Shadowed constructor and static initializer methods must now be annotated
@Implementation
(issue #3122).
Use Robolectric:
testCompile "org.robolectric:robolectric:3.5"
Find more details here. Report issues here. Enjoy!
Robolectric 3.4.2
Robolectric 3.4.2 updates the supported version of Android O to Developer Preview 4.
Robolectric 3.4.1
NOTE: this release has a minor bug and has been superseded by 3.4.2.
Robolectric 3.4
Robolectric 3.4 improves support for Android O Developer Preview 2, PackageManager
, and many other Android classes, and resolves numerous bugs.
Features:
- Improved support for
NotificationManager
features added in Android O [issue #3041]. - Added test APIs for
BatteryManager
[issue #3006]. - Added test APIs for
UserManager
user restrictions [issue #3027]. - Added test API for
PowerManager.newWakeLock()
[issue 3078]. - Added
BackupAgentController
test API for backup agents [issue #3016]. - Added support for
BuildCompat
's version checking methods;Build.VERSION.CODENAME
is now correctly initialized [issue #3031]. - Improved test API and documentation for
ContentResolver
. Configuration.orientation
now matches the orientation indicated by@Config(qualifiers)
[issue #3046].SharedPreferences
uses real Android SDK code rather than a shadow [issue #3051].Robolectric.setupContentProvider()
can now be called with an authority string [issue #3019].- Metadata from manifest is now available for
ContentProvider
s [issue #3022]. - Added support for
SensorManager.createDirectChannel()
. - Added support for
get{Target|Creator}Package()
toShadowPendingIntent
[issue #3033]. - Improved support for
PackageManager.getResourcesForApplication()
[issue #3133]. - Improved support for
PackageManager.queryPermissionsByGroup()
[issue #3160]. - Improved support for
PackageManager.getApplicationInfo()
[issue #3160]. - Improved support for
PackageManager.getProviderInfo()
[issue #3191]. ShadowInputMethodManager
now supports a callback mechanism for soft input visibility changes [Issue #3136].- Added support for several additional methods on
StatFs
[issue #3128]. - Added support for
WifiManager.getPrivilegedConfiguredNetworks()
[issue #3134]. - Added support for
WifiManager#getWifiState()
[issue #3146]. - Added support for
WifiManager#isScanAlwaysAvailable()
[issue #3259]. - Added support for
queryIntentService()
from Manifest [issue #3153]. - Added support for
UserManager.isManagedProfile()
[issue #3154]. - Added
PackageInfo.name
value toActivityInfo
[issue #3159]. - Improved support for
DownloadManager
[issue #3163]. - Added support for
Session.abandon()
[issue #3189]. - Added support for
JobScheduler.getPendingJob(int)
introduced in Android N [issue #3195]. - Added support for ‘ShortcutManager’ [issue #3239].
- Added support for ‘NotificationManager.deleteNotificationChannel’ [issue #3238].
- Support overridden packages with AGP3.0 [issue #3229].
- Make
TempDirectory
shared across entire test env [issue #3199]. - Added support for
AudioManager
andTelephonyManager
[issue #3255]. ShadowService.foregroundStopped
is now reset when a service goes into the foreground [issue #3261].ShadowChoreographer
now allows customized delay to be specified by application forpostCallback
andpostFrameCallback
to avoid animation problems during test [issue #3262].- Added correct
listen()
behavior toShadowTelephonyManager
[issue #3271].
Bug Fixes:
- Fixed a bug in
ShadowLog.getLogs()
andgetLogsForTags()
[issue #3007]. - Supports
targetSdkVersion
ofO
[issue #3037]. - Fixed a bug that caused
Resources.openRawResource()
to throw the wrong exception for missing resources [issue #3059]. - Fixed support for null content values in
ContentResolver
[issue #3067]. - Fixed an issue that caused
Looper
tasks to leak between tests [issue #2963]. - Fixed a bug parsing escape sequences in string resources [issue #3071].
- Fixed a bug that could cause temporary files to leak between tests [issue #3081].
- Fixed a bug that caused
MessageQueue
to block adding messages to the queue while a message was being handled [issue #3082]. - Updated
ShadowSensorManager
andShadowNotificationManager
to be compatible with older SDK versions [issue #3103, #3101]. - Fixed a bug that caused
ActivityManager.getRunningAppProcesses()
to return an empty list instead of null [issue #3124]. - Fixed a bug that prevented
BluetoothDevice
objects from being created [issue #3197]. - Fixed a crash in
WifiConfiguration.toString()
[issue #3144]. - Fixed
Choreographer
constructor for O [issue #3240]. - Fixed race condition in
ShadowSQLiteConnection.reset
[issue #3211]. - Fixed a bug that caused file descriptor leaks [issue #3253].
- Fixed a bug that caused an NPE for some configurations [issue #3220].
- Fixed a bug that caused an NPE if there's a non-directory with the 'values' prefix in
res
[issue #3158].
Misc:
- Robolectric now requires JDK8.
- Removed deprecated
DefaultPackageManager
andRobolectricPackageManager
[issues #3203 and #3264]. - Removed deprecated
org.robolectric.util
controllers [issue #3087]. - Removed deprecated
ShadowConfiguration
[issue #3094]. - Removed deprecated
Transcript
[issue #3113]. - Removed unneeded
*LayoutParams
Shadows [issue #3118]. - Removed deprecated
StubPackageManager
[issue #3151]. - Removed unneeded
*CursorAdapter
Shadows [issue #3117]. - Removed deprecated
ComponentController.attach()
method [issue #3185]. - Removed deprecated
org.robolectric.res.builder.XmlResourceParserImpl
. - Some Robolectric sub-projects have been renamed.
build.gradle
files will need to updated accordingly. [issue #3186]:robolectric-annotations
->annotations
robolectric-junit
->junit
robolectric-processor
->processor
robolectric-resources
->resources
robolectric-sandbox
->sandbox
robolectric-utils
->utils
shadows-core
->framework
shadows-httpclient
->httpclient
shadows-maps
->maps
shadows-multidex
->multidex
shadows-play-services
->playservices
shadows-support-v4
->supportv4
- Deprecated
@Config
attributes that are supplied via new build system API [issue #3230]. - Bumped android stubs to API 26 [issue #3241].
- Removed
RuntimeAdapter
[issue #3218]. - Removed deprecated
ShadowExtractor
,AccessibilityUtil
, andRoboExecutorService
[issue #3174].
Use Robolectric:
testCompile "org.robolectric:robolectric:3.4"
Find more details here. Report issues here. Migration notes here. Enjoy!
Robolectric 3.4 RC5
NOTE: Robolectric 3.4-rc4 is a outdated release candidate; please use 3.4-rc5 instead.