Skip to content

Add Android JUnit coverage for configureAndroidProfiling #6016

Description

@antonis

Context

packages/core/android/src/main/java/io/sentry/react/RNSentryStart.java:186 calls configureAndroidProfiling(options, rnOptions, logger), which reads _experiments.profilingOptions and wires three fields onto SentryAndroidOptions:

  • profileSessionSampleRateoptions.setProfileSessionSampleRate(...) (line 241)
  • lifecycleoptions.setProfileLifecycle(ProfileLifecycle.MANUAL|TRACE) (line 258 / 261)
  • startOnAppStartoptions.setStartProfilerOnAppStart(...) (line 274)

This works correctly today. It has no test coverage. packages/core/android/src/test/ doesn't exist — the Android side of the SDK ships no JUnit tests for the init path at all. The audit run while investigating the iOS profiling bug (#6012) confirmed this gap.

Why this matters

We just finished fixing two iOS bugs (#6012, #6014) where option-parsing code was added to a file that was no longer on the live init path, and XCTest kept passing because it was exercising the dead surface. On Android today, the active init path is correct — but if someone refactors configureAndroidProfiling out of RNSentryStart.startWithOptions, or introduces a parallel init path (as happened on iOS), there is literally no test to catch it. We'd find out from a customer report.

Pinning the wiring with tests would have caught the analogous iOS bug.

What to do

  1. Set up the Android test harness under packages/core/android/src/test/java/io/sentry/react/ with a Robolectric or plain JUnit + Mockito setup (whichever aligns with the rest of the Sentry Android SDK's test conventions — check sentry-java for the pattern).

  2. Wire the test target into packages/core/android/build.gradle so ./gradlew test runs it.

  3. Add RNSentryStartTest (or similar) with at least these cases, mirroring the iOS tests added in fix(profiling): iOS UI profiling on v8 #6012:

    • Passing _experiments.profilingOptions = { profileSessionSampleRate: 1.0, lifecycle: "trace", startOnAppStart: true } results in options.getProfileSessionSampleRate() == 1.0, options.getProfileLifecycle() == ProfileLifecycle.TRACE, options.isStartProfilerOnAppStart() == true.
    • lifecycle: "manual"ProfileLifecycle.MANUAL.
    • No _experiments / no profilingOptions → defaults preserved, no calls made.
    • Invalid types (non-number rate, non-string lifecycle, non-boolean startOnAppStart) → warning logged, value ignored (verify via the logger stub).
  4. Also consider pinning _experiments.enableUnhandledCPPExceptionsV2 handling on Android since it has the same silent-drop risk. (Double-check Android wires it correctly first — the iOS audit only covered iOS.)

  5. Wire the test step into CI (.github/workflows/native-tests.yml has an Android section).

Acceptance

  • ./gradlew test under packages/core/android runs and passes the new tests.
  • CI's Android native-tests workflow runs them too.
  • Deliberately breaking configureAndroidProfiling (e.g. commenting out one of the three options.set… calls) causes the suite to go red.

Notes

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions