Repository navigation
build(android): Run Robolectric unit tests in their own forked task - #6470
Draft
sentry-junior[bot] wants to merge 3 commits into
Draft
sentry-junior[bot] wants to merge 3 commits into
sentry-junior[bot] wants to merge 3 commits into
Conversation
Split the unit tests of sentry-android-core and sentry-android-replay into two tasks. The AGP test task keeps the Robolectric tests and gets a 2g heap and one fork per two CPUs. A new testReleaseJvmUnitTest task runs the other tests with the Gradle defaults. Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>
📲 Install BuildsAndroid
|
With more forks, the test order changes, and a class that ran before this one in the same JVM can leave cached app info without the DSN metadata. Reset it before each test, like the other tests that mock manifest metadata.
… API Use androidComponents.onVariants and the unit test component's configureTestTask instead of afterEvaluate and a task name match. Co-Authored-By: Nelson Osacky <nelson.osacky@sentry.io> Co-Authored-By: Roman Zavarnitsyn <roman.zavarnitsyn@sentry.io>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📜 Description
Adds an
io.sentry.robolectric-test-splitbuild-logic plugin and applies it tosentry-android-coreandsentry-android-replay. It splits each module's unit tests into two tasks:testReleaseUnitTest(the AGP task) runs only the Robolectric tests. It getsmaxHeapSize = "2g"andmaxParallelForks = availableProcessors / 2(at least 1). The plugin now sets core's oldunitTests.all { maxHeapSize = "2g" }.testReleaseJvmUnitTest(new) runs the other tests with Gradle's defaults: one fork and a 512m heap. It uses the same test classes and classpath as the AGP task, andtest/checkdepend on it.A Robolectric test is a class whose own bytecode has
@RunWith(AndroidJUnit4 | RobolectricTestRunner | ParameterizedRobolectricTestRunner). Both modules use only@RunWith(AndroidJUnit4::class)and put it directly on the test class. The bytecode is read with ASM when the task runs, so the split is config-cache safe and needs no per-file list.When you pass
--teststotestReleaseUnitTest, the split is skipped, so running a plain JVM test from Android Studio still works. Gradle has no public getter for the--testspatterns, so this readsDefaultTestFilter.commandLineIncludePatterns, which is an internal API.💡 Motivation and Context
Robolectric tests take most of the unit-test time, and the build scans show that each module's unit tests run in a single executor (
maxParallelForkswas never set). This tries giving only the Robolectric tests more forks and heap, while the plain JVM tests run separately with default settings. Discussed in #team-sdk-java-android.Caching note: both tasks share the same classpath (all test classes), so changing any test class still reruns both. This PR doesn't make caching more granular; that would take separate source sets.
💚 How did you test it?
Locally (JDK 21, 4 CPUs):
:sentry-android-replay:testReleaseJvmUnitTest+:sentry-android-replay:testReleaseUnitTest: 79 tests in 4 classes + 210 tests in 18 classes, no failures. There's no overlap, and the split matches the@RunWith(AndroidJUnit4::class)source files exactly. Two Robolectric executors ran with-Xmx2gand the JVM executor with-Xmx512m. A second run reused the configuration cache.:sentry-android-core:testReleaseJvmUnitTest: 364 tests in 41 classes, no failures. The only non-Robolectric file with@Testit doesn't run is the abstractApplicationExitIntegrationTestBase, whose tests run through its Robolectric subclasses.:sentry-android-replay:testReleaseUnitTest --tests DefaultReplayBreadcrumbConverterTest(a JVM test) runs it.Timing in my sandbox doesn't tell us much. Compare the CI build scan for this PR with
main.📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
sentry-android-core/sentry-android-replaytest task durations and CI memory againstmain, and tunemaxParallelForks(CI runners have 4 CPUs, so this gives 2 forks).DefaultTestFilteruse for the--testspassthrough acceptable, or would we rather drop IDE support for JVM tests throughtestReleaseUnitTest?#skip-changelog
via roman.
--
View Session [Sentry]