Robolectric 4.19-beta-1 is the first beta of 4.19. It adds experimental support for running tests with JUnit Jupiter (JUnit 5 and 6), and support for the Android Keystore on SDK 31 and above.
If you have any issues, please file them here.
Breaking Changes
-
The legacy SQLite mode (
SQLiteMode.Mode.LEGACY, backed by sqlite4java) has been removed. Native SQLite, the default for years, is now always used (#11653). -
RoboCursor,BaseCursorand bothShadowContentResolver.setCursormethods have been deleted (#11852). Use the newContentProviderBuilderinstead, which builds a fakeContentProviderthat returns cursors or file contents forUriMatcherpath patterns and records the queries made to it (#11874):MatrixCursor cursor = new MatrixCursor(new String[] {"name"}); cursor.addRow(new Object[] {"Alice"}); FakeContentProvider provider = ContentProviderBuilder.newBuilder().addCursor("contacts/#", cursor).build(); ContentProviderController.of(provider).create("com.example.contacts");
-
ShadowCursorWindow(#11741) andShadowBuild.setVersionSdkIntFull(#11848) have been removed.
JUnit 5 and 6 support (experimental)
The new org.robolectric:junit-platform artifact runs JUnit Jupiter test classes in Robolectric sandboxes (#11603). Annotate a class with RobolectricExtension, and configure it with @Config as usual:
dependencies {
testImplementation("org.robolectric:junit-platform:4.19-beta-1")
}
tasks.withType<Test>().configureEach { useJUnitPlatform() }@ExtendWith(RobolectricExtension.class)
@Config(sdk = {34, 36})
class MyTest {
@Test
void appName() {
Context context = ApplicationProvider.getApplicationContext();
assertThat(context.getString(R.string.app_name)).isEqualTo("My App");
}
}Jupiter's own features work as usual, including nested, parameterized, repeated and dynamic tests, and third-party extensions such as MockitoExtension. Tests that run on several SDKs are reported under the name of each SDK (#11808, #11813).
JUnit 5.14 and later, and JUnit 6, are supported (#11810). JUnit 6 requires Java 17.
Projects can migrate one class at a time. Keep junit-vintage-engine on the test runtime classpath, and JUnit 4 classes keep running with their own runners, sharing sandboxes with the Jupiter tests (#11806). JUnit 4 rules don't run under Jupiter, so a Jupiter class that still has a @Rule or @ClassRule (such as HiltAndroidRule) now fails with an explanation instead of silently skipping the rule (#11812).
The API may change before it is stable, so please try it and tell us how it goes.
Android Keystore support
KeyStore.getInstance("AndroidKeyStore") now works on SDK 31 and above, so tests can generate and use keys with the real Android APIs instead of mocking KeyStore, KeyGenerator and Cipher (#11826):
KeyGenerator generator = KeyGenerator.getInstance(KeyProperties.KEY_ALGORITHM_AES, "AndroidKeyStore");
generator.init(
new KeyGenParameterSpec.Builder("secret", KeyProperties.PURPOSE_ENCRYPT | KeyProperties.PURPOSE_DECRYPT)
.setBlockModes(KeyProperties.BLOCK_MODE_GCM)
.setEncryptionPaddings(KeyProperties.ENCRYPTION_PADDING_NONE)
.build());
SecretKey key = generator.generateKey();Robolectric runs the framework's own AndroidKeyStore provider on top of a software keystore2 daemon. It supports AES, HMAC, RSA and EC keys, and enforces key parameters like a device does: purposes, block modes, paddings, digests, usage counts and StrongBox availability (following FEATURE_STRONGBOX_KEYSTORE).
User authentication requirements are enforced too, and there is no new test API for them. The existing lock screen, biometrics and BiometricPrompt shadows drive them: a successful prompt authorizes the key, removing enrolled biometrics invalidates keys bound to them, and removing the lock screen invalidates keys that require authentication.
The provider is installed by default. If your tests install their own AndroidKeyStore provider, set the system property robolectric.enableAndroidKeyStore to false and Robolectric leaves the security providers alone.
Other Highlights
- Framework code can read the real wall clock by setting
robolectric.useRealWallClock=true, soDateUtils.isTodayand notification timestamps are no longer near 1970. This will be the default in a future release (#11871). AppWidgetHostViewappliesRemoteViewsas the framework does (#11866).ShadowLooper.shadowMainLooper()is deprecated (#11742).
What's Changed
- Remove the AVD snapshot cache from the instrumentation tests by @copybara-service[bot] in #11641
- Save Gradle caches for the google branch workflows by @copybara-service[bot] in #11645
- Add actionlint GitHub Actions workflow and fix workflow lint issues by @hoisie in #11647
- Bump version to 4.19-SNAPSHOT by @hoisie in #11651
- Assign unused result of simpleQueryForString in SQLiteStatementTest by @hoisie in #11654
- Check staged releases on Linux arm64 by @hoisie in #11652
- Check that bitmap native allocations are freed deterministically by @hoisie in #11648
- Start the generated release notes from the previous release by @hoisie in #11650
- Download the android-all jars instead of caching them by @hoisie in #11649
- Allow point releases from an older release branch by @hoisie in #11655
- Add AGENTS.md by @utzcoz in #11632
- Add an "agents welcome" badge and an agents section to the README by @hoisie in #11658
- Add source-specific
setPhoneNumbersupport toShadowSubscriptionManagerby @copybara-service[bot] in #11660 - Remember loaded classes in SandboxClassLoader.isClassLoaded by @hoisie in #11662
- Replace the Mockito mocks in testReplacementFontMetricsTest by @hoisie in #11659
- Only save the Gradle cache from the test jobs by @hoisie in #11661
- Set ownerUid on displays created via ShadowDisplayManager and ShadowDisplayManagerGlobal by @copybara-service[bot] in #11664
- Fix NullArgumentForNonNullParameter findings by @utzcoz in #11657
- Make windows on non-default displays follow their display's configuration by @utzcoz in #11566
- Remove dev container configuration by @utzcoz in #11667
- Require signing when publishing a release to a Maven repository by @brettchabot in #11337
- Cherry-pick PRs into the google branch too by @hoisie in #11669
- Run the vector drawable golden tests on SDK 35 and later by @hoisie in #11665
- Add cursor position coverage for scale, offset, copy and parcel by @abhinav-phi in #11608
- Launch the target of an activity alias in the simulator by @hoisie in #11671
- Launch the app's own launcher first in the simulator by @hoisie in #11673
- Serialize Maven dependency downloads within the JVM by @utzcoz in #11672
- Wrap long line in build-logic README by @hoisie in #11676
- Follow Java naming conventions in CppAssetManager2 by @hoisie in #11675
- Don't break Gradle builds that apply the simulator plugin by @hoisie in #11674
- Revert "Check that bitmap native allocations are freed deterministically" by @hoisie in #11679
- Close the cursor used by FakeMediaProvider.getType by @utzcoz in #11680
- Reject speech after TextToSpeech shutdown by @utzcoz in #11685
- Preserve empty slots when copying a resource theme by @zacsweers-oai in #11595
- Don't build the app's APK before running the simulator by @hoisie in #11682
- Detach PixelCopy canvases before releasing their bitmaps by @zacsweers-oai in #11596
- Update Gradle to v9.9.0 by @renovate[bot] in #11702
- Update roborazzi to v1.78.0 by @renovate[bot] in #11703
- Cover fullscreen Compose fragment insets by @utzcoz in #11694
- Update dependency com.diffplug.spotless:spotless-plugin-gradle to v8.11.0 by @renovate[bot] in #11699
- Update dependency com.google.guava:guava-testlib to v33.8.0-jre by @renovate[bot] in #11700
- Update dependency com.googlecode.libphonenumber:libphonenumber to v9.0.43 by @renovate[bot] in #11697
- Update dependency io.mockk:mockk to v1.14.12 by @renovate[bot] in #11698
- Update dependency com.android.tools.build:gradle to v9.5.1 by @renovate[bot] in #11696
- Update dependency com.android.tools:common to v32.5.1 by @renovate[bot] in #11695
- Update dependency org.conscrypt:conscrypt-openjdk-uber to v2.9.0 by @renovate[bot] in #11701
- Back Surface.copyFrom(SurfaceControl) with an ImageReader under real draw. by @copybara-service[bot] in #11704
- Keep a valid SurfaceControl for windows that aren't visible on SDK 37+. by @copybara-service[bot] in #11705
- Skip types with a mobile country code when filtering configs by @hoisie in #11678
- Tolerate host rounding in the repeated-arc vector golden by @utzcoz in #11686
- Replace bitmap stress test with a process memory check by @hoisie in #11681
- Show the simulator's window when it's started from a test by @hoisie in #11683
- Add a temporary opt-out for RuntimeShader scalar uniform forwarding by @hoisie in #11707
- Compile the native graphics tests for Java 17 by @hoisie in #11708
- Forward RuntimeShader scalar uniform setters to native code on SDK 33 and 34 by @copybara-service[bot] in #11711
- Test Mac x86_64 on Apple Silicon under Rosetta 2 instead of Intel by @hoisie in #11710
- Find Robolectric in testImplementation for the simulator dependency by @hoisie in #11712
- Stop publishing a kotlin-stdlib dependency from the simulator plugin by @hoisie in #11715
- Install a default uncaught exception handler in the simulator by @hoisie in #11718
- Download the android-all jars from Google's Maven Central mirror first by @hoisie in #11720
- Map the Escape key to Back in the simulator by @hoisie in #11719
- Forward the unit test heap size to the simulator by @hoisie in #11717
- Exit the simulator when building the sandbox fails by @hoisie in #11713
- Only apply the display override to an activity's current configuration by @hoisie in #11721
- Allow applying the simulator plugin before the Android plugin by @hoisie in #11714
- Map trusted and focus virtual display flags to display flags by @hoisie in #11722
- Remove configuration listeners at instrumentation teardown by @utzcoz in #11693
- Respect the requested window size in the simulator plugin by @hoisie in #11716
- Preserve resource IDs when cloning state list drawables by @utzcoz in #11691
- Scope Maven download locks to the local repository by @utzcoz in #11677
- Notify callbacks when network capabilities change by @utzcoz in #11692
- Index shadow methods per shadow class instead of scanning them on every lookup by @MGaetan89 in #11723
- Add Commons Logging classloading integration tests by @utzcoz in #11690
- Update dependency org.apache.santuario:xmlsec to v2 [SECURITY] by @renovate[bot] in #11728
- Add regression test for Material dynamic colors by @utzcoz in #11725
- Pass shareableActivityToken in ActivityReflector#callAttach by @copybara-service[bot] in #11729
- Draw SurfaceViews in ShadowPixelCopy when they have no real Surface by @copybara-service[bot] in #11740
- Register APP_SEARCH_SERVICE in ShadowServiceManager on SDK 36+ by @copybara-service[bot] in #11738
- Enable APP_FUNCTION_SERVICE by default in ShadowServiceManager on SDK 36+ by @copybara-service[bot] in #11739
- Remove the legacy SQLite mode by @hoisie in #11653
- Install manifest content providers at startup in the simulator by @hoisie in #11731
- Stop registering legacy vector drawable groups and paths by @hoisie in #11727
- Remove ShadowCursorWindow by @hoisie in #11741
- Share immutable resource values across bags and themes by @zacsweers-oai in #11726
- Add Fragment Compose teardown regression test by @utzcoz in #11735
- Update the README to Robolectric 4.18 by @hoisie in #11744
- Shadow bindServiceCommon instead of the bindService overloads by @hoisie in #11732
- Open a PR to update the README in the release workflow by @hoisie in #11745
- Add StAX service provider regression tests by @utzcoz in #11754
- Add PowerMock Application regression test by @utzcoz in #11755
- Add ViewPropertyAnimator listener regression test by @utzcoz in #11753
- Test WebView hosting in Compose AndroidView by @utzcoz in #11730
- Move the Central Portal upload step of the release workflow to Python by @hoisie in #11747
- Draw paused activities in UiAutomation screenshots by @hoisie in #11749
- Hook up HardwareRenderer frame metrics observers to HWUI on SDK 37 by @hoisie in #11757
- Add an option to bind to the app's real services by @hoisie in #11748
- Fix existing errorprone issues by @utzcoz in #11666
- Deprecate ShadowLooper.shadowMainLooper() by @utzcoz in #11742
- Enable CheckReturnValue with errorprone default by @utzcoz in #11759
- Wait on the class monitor in ShadowServiceManager.waitForService by @hoisie in #11758
- Add an opt-in default uncaught exception handler by @hoisie in #11734
- Match Android pixel channel order in native buffers by @utzcoz in #11687
- Run SecurityProvidersTest against a local HTTPS server by @hoisie in #11760
- Put robolectric-deps.properties on the classpath of Android unit tests by @hoisie in #11761
- Fall back to Google's mirror when Maven Central fails to serve an SDK by @hoisie in #11768
- Update dependency org.apache.santuario:xmlsec to v4 by @renovate[bot] in #11772
- Run only the test JVMs under Rosetta 2 in the Mac x86_64 job by @hoisie in #11767
- Handle mouse and keyboard input in a headless simulator by @hoisie in #11750
- Make the GlobalConfigProvider optional for ConfigConfigurer by @hoisie in #11752
- Read GRADLE_MAX_PARALLEL_FORKS with a plain if by @hoisie in #11773
- Dispose Choreographer display receivers by @utzcoz in #11688
- Fix lint warnings in CppAssetManager2 and Asset by @hoisie in #11774
- Update dependency commons-logging:commons-logging to v1.4.0 by @renovate[bot] in #11766
- Update dependency app.cash.molecule:molecule-runtime to v2.2.0 by @renovate[bot] in #11764
- Update roborazzi to v1.79.0 by @renovate[bot] in #11771
- Install content providers for lazily created applications by @hoisie in #11775
- Make robolectric.* system properties inputs of the test tasks by @hoisie in #11776
- Update Gradle to v9.9.1 by @renovate[bot] in #11762
- Update dependency com.google.android.material:material to v1.14.0 by @renovate[bot] in #11765
- Update ksp monorepo to v2.3.14 by @renovate[bot] in #11763
- Update dependency org.bouncycastle:bc-jdk18on-bom to v1.87 by @renovate[bot] in #11770
- Block credential storage access while user is locked by @utzcoz in #11743
- Add cache quota, allocatable bytes, and path UUIDs to ShadowStorageManager. by @copybara-service[bot] in #11736
- Prefer reflectors over ReflectionHelpers in AGENTS.md by @hoisie in #11781
- Fix ShadowPausedLooper scheduled task time queries and run them on the Looper thread by @copybara-service[bot] in #11780
- Advance ShadowSystemClock by render idle duration in Simulator loop. by @copybara-service[bot] in #11783
- Make shadow methods accessible once when indexing them by @hoisie in #11784
- Return a read-only view from getNetworkCallbacks by @hoisie in #11779
- Use an SVG version of the logo in the README by @hoisie in #11785
- Stop making shadow methods accessible when linking call sites by @hoisie in #11786
- Add fingerprint authentication error support by @utzcoz in #11777
- Update the README to Robolectric 4.18.1 by @github-actions[bot] in #11790
- Fix shadow instrumentation for incompatible constructors by @jselbo in #11229
- Make ShadowValueAnimatorTest.start_shouldRunAnimation run the animation by @MGaetan89 in #11787
- Raise the minSdk of test apps and manifests to 24 by @MGaetan89 in #11788
- [Prototype] JUnit Platform engine for Robolectric (see #10897) by @geoadaMeta in #11603
- Remove redundant minSdk = N from shadow and test annotations by @MGaetan89 in #11789
- Parallelize class instrumentation in JarInstrumentor by @copybara-service[bot] in #11804
- Use Zipflinger in JarInstrumentor to zero-copy unchanged entries by @copybara-service[bot] in #11805
- Raise the minSdk of the simulator plugin test project to 24 by @MGaetan89 in #11803
- Make the simulator plugin compatible with the configuration cache by @hoisie in #11794
- Remove SDK checks that are always true now that the minimum SDK is 24 by @MGaetan89 in #11802
- Skip constructor instrumentation that would not verify by @hoisie in #11796
- Fix ArrayIndexOutOfBoundsException in Environment.isExternalStorageManager by @hoisie in #11793
- Don't hang the simulator's exit when recording a frame fails by @hoisie in #11792
- Use reflectors in ShadowNativeHardwareRendererObserverTest by @hoisie in #11782
- Return a default ANDROID_ID from Settings.Secure by @hoisie in #11791
- Relayout existing windows when real draw traversals are enabled by @hoisie in #11733
- Resolve the simulator in its own configuration by @hoisie in #11795
- Run JUnit 4 classes on JUnit Vintage, sharing sandboxes with the engine by @hoisie in #11806
- Reuse parameter providers within each sandbox by @utzcoz in #11689
- Name Jupiter tests that run on several SDKs after the SDK by @hoisie in #11808
- Advance the clock after the frame when a frame is scheduled during one by @hoisie in #11807
- Support JUnit 5.14 in the junit-platform engine by @hoisie in #11810
- Build the junit-platform engine against JUnit 5.14 by @hoisie in #11811
- Turn on Conscrypt in the simulator by @hoisie in #11815
- Handle grantInputChannel in ShadowWindowManagerGlobal on API >= 37 by @copybara-service[bot] in #11816
- Dispatch onCameraRemoved in ShadowCameraManager.removeCamera on API 37+ by @copybara-service[bot] in #11818
- Prefer Bouncy Castle to the JDK's security providers by @hoisie in #11814
- Update enabled state of pinned shortcuts by @wozhenbang2004 in #11819
- Replace extras when updating a PendingIntent by @wozhenbang2004 in #11820
- Add home TZ offset change notifications capability to ShadowTimeManager. by @copybara-service[bot] in #11706
- Fail Jupiter tests whose classes have JUnit 4 rules by @hoisie in #11812
- Report Jupiter tests by class instead of by sandbox by @hoisie in #11813
- Remove unnecessary
@ClassNameusages by @MGaetan89 in #11417 - Reference VsyncEventData directly in ShadowPausedNoVsyncChoreographer by @hoisie in #11824
- Create
ClassNameValidatorto report@ClassNameusages that can reference the class directly by @MGaetan89 in #11416 - Report Jupiter @nested classes once instead of once per sandbox by @hoisie in #11821
- Don't report JUnit 3 warnings for Jupiter classes that extend TestCase by @hoisie in #11823
- Treat resource package IDs and resource IDs as unsigned by @utzcoz in #11828
- Update Gradle to v9.9.2 by @renovate[bot] in #11833
- Update Android Gradle Plugin by @renovate[bot] in #11830
- Add
com.android.tools.build:gradletorenovate.jsonby @MGaetan89 in #11836 - Update dependency com.googlecode.libphonenumber:libphonenumber to v9.0.44 by @renovate[bot] in #11832
- Run dynamic feature module tests against the base app by @hoisie in #11829
- Add ShadowBuild.setVersionSdkIntFull and ApplicationExitInfoBuilder.setSubReason by @copybara-service[bot] in #11817
- Support multiple split APKs in DefaultManifestFactory by @utzcoz in #11837
- Reuse cached native library in the first sandbox by @joshfriend in #11585
- Bind invokedynamic call sites to their targets without a SwitchPoint guard by @rossbacher in #11845
- Remove the unused mode invalidation hook from Sandbox by @hoisie in #11847
- Remove ShadowBuild.setVersionSdkIntFull by @copybara-service[bot] in #11848
- Render PixelCopy screenshots straight into a matching destination by @rossbacher in #11844
- Look up sandbox classes and resources through the parent only by @hoisie in #11842
- Replace the destination when a PixelCopy from a surface resizes by @rossbacher in #11850
- Implement PackageInstaller.Session.getNames() in ShadowPackageInstaller by @utzcoz in #11851
- Ignore color mode qualifiers before O by @hoisie in #11865
- Add a ConstraintLayout Group visibility test to the androidx integration tests by @MGaetan89 in #11853
- Fix configuration change visibility by @utzcoz in #11668
- Deliver ResultReceiver.send from a parcelled copy by @yschimke in #11855
- Allow PixelCopy.request from any thread under real draw traversals by @yschimke in #11857
- Bump compileSdk to 37.1 for integration tests and release-check by @utzcoz in #11868
- Find classes on a long class path through a package index by @rossbacher in #11846
- Update dependency androidx.compose:compose-bom to v2026.11.01 by @renovate[bot] in #11834
- Name NetworkInfo's type and subtype by @yschimke in #11854
- Remove deprecated BaseCursor, RoboCursor, and ShadowContentResolver.s… by @utzcoz in #11852
- Construct the Bouncy Castle provider on a background thread by @AlexanderGH in #11838
- Check framework timestamps without assuming the virtual clock by @hoisie in #11870
- Share AlarmManager and JobScheduler state across contexts by @yschimke in #11858
- Record an activity's picture-in-picture params by @yschimke in #11859
- Let Bouncy Castle read version 1 BKS key stores by @yschimke in #11877
- Keep UiAutomation screenshots and input on their display by @yschimke in #11863
- Advance the clock in tests with ShadowSystemClock.advanceBy by @hoisie in #11873
- Give framework code the real wall clock by @hoisie in #11871
- Read PackageManager properties from the manifest by @yschimke in #11861
- Keep an APK's targetSdkVersion when there is no manifest file by @yschimke in #11872
- Skip loading the device's aconfig flag files on V by @hoisie in #11883
- Remove an activity's remaining windows when it is destroyed by @yschimke in #11878
- Drive a looper through the TestLooperManager that already holds it by @yschimke in #11879
- Check that bitmap memory is freed by its own mappings by @hoisie in #11885
- Let AppWidgetHostView apply RemoteViews as the framework does by @yschimke in #11866
- Check the results of java.lang.invoke methods with Error Prone by @hoisie in #11886
- Make ShadowPosix's stat methods instance methods like Posix's by @hoisie in #11887
- Check only ManifestProperties' logs in a getProperty test by @hoisie in #11888
- Add ContentProviderBuilder for tests that need a cursor or file by @hoisie in #11874
- Support the Android Keystore on SDK 31+ by @hoisie in #11826
- Wait longer for staged artifacts in the release check by @hoisie in #11889
New Contributors
- @abhinav-phi made their first contribution in #11608
- @github-actions[bot] made their first contribution in #11790
- @wozhenbang2004 made their first contribution in #11819
- @joshfriend made their first contribution in #11585
- @rossbacher made their first contribution in #11845
Full Changelog: robolectric-4.18.1...robolectric-4.19-beta-1