Releases: robolectric/robolectric
Robolectric 4.4 Alpha 2
NOTE: Robolectric 4.4-alpha-2 is a outdated preview release; please use 4.4 or later instead.
Robolectric 4.4 Alpha 1
NOTE: Robolectric 4.4-alpha-1 is a outdated preview release; please use 4.4 or later instead.
Robolectric 4.3.1
Robolectric 4.3.1 adds support for Android API 29 (Q final).
Compatibility
- Running tests on Android API 29 now strictly requires a Java9 runtime or newer. If you are seeing errors about unsupported Java version when running tests on API 29 via Android Studio; you can use the 'JRE' field in the Run Configuration dialog to configure a newer Java runtime. See https://developer.android.com/studio/run/rundebugconfig for more background.
Robolectric 4.3
This release introduces a new PAUSED Looper mode, enhanced Espresso compatibility, support for Android Q Beta 2, and numerous SDK support improvements and bug fixes
Features
- Support Android Q beta 2 (build 5415296). [1717fb1]
- Support for new
PAUSED
Looper
mode. - Support clicking menu items via Espresso [issue #4889]
- More realistically measure and layout Android text views
Android SDK support and Test API changes
- Use real OverScroller in PAUSED LooperMode. [4337639]
- Add ShadowDevicePolicyManager#isLockTaskPermitted(String).
- Add Locale methods to Shadow for CaptioningManager.
- Add enabling/disabling data in ShadowTelephonyManager. [issue #4844]
- Add an initial shadow for the LauncherApps System Service. [issue #4837]
- Add ShadowUserManager.removeUser(UserHandle) [issue #4854]
- Add IntentSenderRequest for startIntentSenderForResult methods. [issue #4870]
- Shadow night display ColorDisplayManager methods
- Add getPasswordComplexity support to ShadowDevicePolicyManager [issue #4878]
- Add shadow implementation for ShadowDexFile.isDexOptNeeded. [issue #4886]
- Shadow DisplayManagerGlobal#getStableDisplaySize [issue #4838]
- Shadow ContextImpl.startActivityAsUser [issue #4899]
- Shadow implementation of android.hardware.HardwareBuffer [issue #4895]
- Add shadow for ShadowAppOpsManager#noteProxyOpNoThrow. [issue #4906]
- Add support for new Android Q fields to EventBuilder [issue #4905]
- Add support for UsageStatsManager#getUsageSource() [issue #4920]
- Support stopForeground(int) in ShadowService. [issue #4919]
- Support ShadowSensor#getMaximumRange [issue #4881]
- Add support for passing resultCode through to broadcasts intents [issue #4917]
- Fix activities leaking between test cases [issue #4930]
- Fall back to Android's implementation of PackageManager.getPackageArchiveInfo [issue #4928]
- Add ShadowPausedAsyncTask#overrideExecutor API to replace waitForIdle. [issue #4950]
- Add API
ShadowApplicationPackageManager.getLeanbackLaunchIntentForPackage()
(wrapsgetLaunchIntentForPackage()
) [c16c3bf] - Add new shadow
Looper
APIs for retrieving the scheduled time for tasks. [6494bde] - Added Robolectric shadow for
TotalCaptureResult
. [8e1e585] - Add
ShadowLooper#isIdle
[f4a5d49] - Create APIs for executing tasks on real background threads in
PAUSED
looper mode. [d29bf89] - Add
get
/setLockTaskPackages
support toDevicePolicyManager
[b1ecc5a] - Add implementation of -
ShadowSubscriptionManager#getAvailableSubscriptionInfoList
-ShadowSubscriptionManager#setAvailableSubscriptionInfoList
-ShadowSubscriptionManager#setAvailableSubscriptionInfos
-SubscriptionInfoBuilder#setMnc
[95bac4a] - Modify
ShadowLocationManager
to respectLOCATION_MODE
. [348d0d2] - Make
ActivityController#recreate
aware of the current lifecycle state [7cc5b42] - Implement
ActivityManager#isBackgroundRestricted()
[4cbe349] UiModeManager
[78a4eec]- Set different values for each of
OsConstants
errno
values [aeadc29] - Add ShadowIsoDep [2e94093]
- Add
ShadowBluetoothGatt.connect()
[8cffa29] - Implement
SubscriptionManager.getPhoneId()
with a map between subscription IDs and phone IDs. [01ea680] - Add torch setting capabilities to
ShadowCameraManager
. [f25ec77] - Add method to
ShadowContextWrapper
to expose the options of the most recently started activity [da1bace] - Add
setInMultiWindowMode()
to change multi window state forShadowActivity
. [9b2af0b] - Supports
setProfileClass
&setIsEmbedded
inSubscriptionInfoBuilder
[4c74611] - Supports
EuiccManager#getEid
inShadowEuiccManager
[e64f675] - Fake out a minimal implementation of
ShadowSliceManager.getPinnedSlices()
. [2f7aa83] - Add
setSeedAccountType()
forShadowUserManager
[70d712f] - Allow delivering broadcasts by class name. [665000d]
- Add shadow for
ColorDisplayManager
per-app grayscale [095c527] - Add
ShadowApplication#clearRegisteredReceivers
helper method [c0d1719] - Enhance
ShadowBroadcastReceiver
to allow testing async receivers [78c3998] - Add
supportsMultipleUsers()
&setSupportsMultipleUsers()
forShadowUserManager
[50ec6ed] - Support tag in
ShadowWakeLock
[3137c1c] - Add
createConfirmFactoryResetCredentialIntent
toShadowKeyguardManager
[1d20033] ShadowInputDevice
: Add shadow implementation for thegetProductId()
andgetVendorId()
methods. [8aa09a5]- Add
switchUser(UserHandle)
forShadowActivityManager
[7a63796] - Creating a Shadow for
NetworkCapabilities
. The current implementation only overrides fetching and updation of transport. [d432dcf] - Allow
ShadowEvent
to set thread id as well. [ff84723] - Add partial (backward)
@Implementation
ofgoBackOrForward(steps)
toShadowWebView
[a616926] - Create a Shadow for
SigningInfo
, which was added in API 28. [dd1d408] - Implement
ShadowBinder.setCallingUserHandle()
/Binder.getCallingUserHandle()
[aaa393b] - Support
ShadowBluetoothDevice.connectGatt()
overloads. [7d95ef4] - Implement
AccountManager.removeAccount(...)
withActivity
parameter. [63816d7] - Fix
ShadowMediaPlayer.setDataSource(MediaDataSource)
[c3037c1] - add missing shadow of
MediaPlayer.setDataSource(MediaDataSource)
[2876f57] - Add
getDefault{X}SubscriptionId()
equivalents for older versions of Android toShadowSubscriptionManager
. [daa72ae]
Configuration
- Introduced an opt-in mode that fixes zero-sized
TextView
s in Robolectric [9bfa258] - Move ConfigurationRegistry into shadowsapi [b5e63df]
- Added extension points to
AndroidEnvironment
andClassInstrumentor
[3604e42]
Bug Fixes
- Fix another 'NoSuchMethodError java.nio.ByteBuffer.position' issue in Java8 [804b89a]
- Fix concurrent modification exception in ShadowAlarmManager [03fd8c3]
- Fixed transliteration problems where cpp copy assignments were transliterated as java reference copies
- Propagate RemoteException from Binder#onTransact method
- Fix AccessibilityNodeinfo.obtation(NodeInfo) to clone Extra correctly [issue #4865]
- Protecting ShadowSensorManager.sendSensorEvent from ConcurrentModificationException [issue #4839]
- Synchronize cleanup of ApkAssets cache with corresponding native object [issue #4910]
- Fix a bug causing flakes when using ShadowSQLiteConnection. [issue #4904]
- Fix typing text into phone EditText fields. [issue #4909]
- Includes st_mode in Os.stat/lstat/fstat system calls. [issue #4915]
- Fixed an issue where nine patch chunks are overridden [issue #4914]
- Ensure ActivityScenario lifecycle events are consistent with device. [issue #4954]
- Make Instrumentation.runOnMainSync behave consistently with device. [issue #4951]
- Make sure that ShadowAccountManager doesn't crash on empty features. [issue #4953]
- Initialize Robolectric environment location properly. [72fa419]
- Introduced an opt-in mode that fixes zero-sized
TextView
s in Robolectric [9bfa258] - Oops, missed a Q Beta 1 shadow. [04db5d5]
- Don't instrument
androidx.room.CoroutinesRoom$Companion
. [6d24639] - Stem
CachedDependencyResolverFileCacheTest
flakiness by increasing valid cache time. [10acb64] - Windows actually works finally, maybe [issue #4605].
- Fixes bug in activity lifecycle state transition with finish() in onCreate [7e0d8c1]
- Apply fixes from
LocalActivityInvoker
toRoboMonitoringInstrumentation
. [017559d]
Deprecations and Removals
@Deprecate
a bunch of methods inShadowView
where alternatives exist in Espresso [312376d]
Internal Changes
- Updated to AndroidX Test 1.2.0 [47c0736]
- Restructure ShadowLooper and related shadows into a abstract base 'API' class, and two subclasses: ShadowLegacy* and
ShadowPaused*. A shadowPicker will be used to pick the correct shadow to use based on LooperMode. - Exclude Arch Components and Room from Shadows [issue #4883]
- Break org.robolectric:annotations -> org.robolectric:shadow-api dependency [issue #4948]
- Rename
(Android)?Environment
to(Android)?TestEnvironment
. [6308e4f] [issue #4850] - Idle main looper after each
SupportFragmentTestUtil
call when looper mode isPAUSED
. [78d27a9] - Added missing native functions in
ShadowRenderNode
[7740562] - Add
setExecutor
shadow API [1e2c79c] - Introduce a new "Paused looper" threading model. [acb7af7]
- Change
ShadowNativeAllocationRegistry
to use loose signatures [5409c0d] - Create a
LooperMode
configurer annotation. [8e26be1] - Enable
callThroughByDefault
forNativeAllocationRegistry
, and explicitly shadow methods instead. [1f5f0fe] - Allow
ShadowAppOpsManager#toOpEntry
to be overridden, and makeTestUtil
use injectedDependencyResolver
andSdkProvider
. [adad503] - Refactor exception-message assertions to use
ThrowableSubject.hasMessageThat()
. [729acc2] - Add link to github issue explaining workaround. [9ef6e60]
- Attempt 2 at clearing exception handler. [2fd0a1b]
- Merge pull request #4736 from robolectric/undeclared-activtiy-workaround [a4275f1]
- Internal change [f662314]
- Aggregate test results from all projects. [65b0975]
- Ignore mysterious AGP fail: [1b0d479]
- Test for AGP manifest bug workaround. [6d57524]
- Make it clear that
Util.sneakyThrow()
disrupts program flow. [316e3f0] - Remove
ShadowHandler
- it is an empty implementation now. [bcbf11d] - Fix
ShadowAppOpsManager.toOpEntry()
compilation. [37d9948] - Merge pull request #4645 from robolectric:jakew/sneaky-throw/2019-02-17 [91af73f]
- Internal change [f3980e1]
- Fix call order of
postCreate()
and sta...
Robolectric 4.3 Beta1
NOTE: Robolectric 4.3-beta-1 is a outdated preview release; please use 4.3 or later instead.
Robolectric 4.3 Alpha 3
NOTE: Robolectric 4.3-alpha-3 is a outdated preview release; please use 4.3 or later instead.
Robolectric 4.3 Alpha 2
NOTE: Robolectric 4.3-alpha-2 is a outdated preview release; please use 4.3 or later instead.
Robolectric 4.2.1
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.
Bug Fixes
- Robolectric 4.2.1 fixes a number of issues when running tests on Windows [issue 4670].
- Applied fixes to activity lifecycle
RoboMonitoringInstrumentation
[4c7f968].
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.
- 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.1"
Find more details here. Report issues here. Enjoy!
Robolectric 4.3 Alpha 1
NOTE: Robolectric 4.3-alpha-1 is a outdated preview release; please use 4.3-alpha-2 or later instead.
Robolectric 4.2
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; seePackageManager.addOrUpdateActivity()
andremoveActivity()
, plusService
,ContentProvider
, andBroadcastReceiver
equivalents [issue #4489].- Implement
PackageManager.isSafeMode()
[issue #4526].
ShadowDisplayManager.getSaturationLevel()
is now an instance method [issue #4522].- Telephony
- Add
slotId
basedgetImei()
andgetMeid()
toTelephonyManager
[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].
- Add
- Bluetooth
- Test
APIs
forBluetoothSocket
andBluetoothServerSocket
connections [issue #4510]. - Implement
BluetoothLeAdvertiser
[issues #4478 and #4454]. - Implement
BluetoothHeadset.getConnectedDevices()
,getConnectionState()
, andsendVendorSpecificResultCode()
, with test APIs [issue #4442]. - Add ability to send BluetoothGattCallback connection state change updates [issue #4584].
- Test
- Implement
ActivityManager#getCurrentUser()
[issue #4483]. UserManager
- Implement
Context.sendBroadcastAsUser
[issue #4486]. - Implement
WindowManagerImpl#removeViewImmediate(View)
[issue #4447]. - Implement
SensorManager.registerListener()
: [issue #4446]. - Implement
NetworkScoreManager.disableScoring()
andisScoringEnabled()
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
andRangingResult
[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
andMediaMuxer
shadows to robolectric. TheMediaCodec
shadow implements basic passthrough asynchronous encoding, and theMediaMuxer
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 ofRuntimeException
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 calledActivity.onRetainNonConfigurationInstance()
directly to obtainnonConfigInstance
for the activity. This should've called indirectly fromActivity.retainNonConfigurationInstances().
retainNonConfigurationInstances()
also createsnonConfigInstances
for fragments to prepare for the host activity recreation [issue #4511]. - Fix timeout in
FontsContract.getFontSync()
caused becauseContext.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 withApplicationInfo#processName
[issue #4537]. - Throw
NameNotFoundException
from Context.createPackageContext
for non-existing packages [issue #4527]. - Synchronize access to
ShadowPendingIntent
andShadowUsageStatsManager
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 useShadowPackageManager.addOrUpdateActivity(ActivityInfo)
[issue #4489].- Deprecate Robolectric#
setupActivity
in favor ofActivityScenario
[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. FixSDK
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
fromSdkConfig
[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!