0

When running UI tests with the SFMCSdk initialized I always get an ANR:

ANR in my.package.android
PID: 3250
Reason: executing service my.package.android/com.google.android.gms.measurement.AppMeasurementService
Load: 0.0 / 0.0 / 0.0
----- Output from /proc/pressure/memory -----
some avg10=0.00 avg60=0.00 avg300=0.00 total=454493
full avg10=0.00 avg60=0.00 avg300=0.00 total=191367
----- End output from /proc/pressure/memory -----

How I initialize the SDK:

SFMCSdk.configure(
    applicationContext,
    SFMCSdkModuleConfig.build {
        pushModuleConfig = MarketingCloudConfig.builder().build(applicationContext)
    }
)

When I comment out this line then my UI tests are running as expected.

Might be interesting to mention that I am using compose in my tests:

@get:Rule
val composeTestRule = createAndroidComposeRule<MainActivity>()

1 Answer 1

1

I'm not sure how the SDK would affect your test execution unless you're doing things that rely on it in those activities. One of the first things that the SDK does is spin up an init thread and return execution to your application.

Here's a sample application showing a timer, and you can see that execution is returned to your application before anything else happens with regards to the SDK's initialization ... enter image description here

4
  • Found out that a ANR was coming from a wrongly set up of the SFMCSdk, I was missing the application ID and other things, so when I ran the app I got a crash but in the UI test I only got an ANR. After fixing this I still have the problem that my UI tests are stuck and no action is performed by the UI test, it is only stuck on the first screen. After I remove the initialization for salesforce the tests are running fine.
    – Kata
    Commented Oct 4, 2022 at 7:15
  • The SDK is initialized in your application class, and I've shown you how to determine if there's some blocked execution path (which there is not). If, however, your activity has code relying on the SDK, SFMCSdk.requestSdk { /* stuff */ }, then the activity would have to wait until the SDK finished initializing before that code block would execute. It is possible (likely?) that SDK initialization failed and the SDK is never returned to the request for it. In all cases, including your original question, logging is your friend. Enable logging and review the logcat.
    – Bill Mote
    Commented Oct 4, 2022 at 12:43
  • 1
    You were correct the issue was around SFMCSdk.requestSdk { /* stuff */ } and not with the initalization. Something was there blocking everything.
    – Kata
    Commented Oct 4, 2022 at 15:14
  • If the SDK does not successfully initialize, which would have definitely been the case before you fixed the appId issue, then it will never execute the WhenReadyListeners. Enable SDK logging and review the logs. If it's failing to initialize it will tell you exactly why.
    – Bill Mote
    Commented Oct 5, 2022 at 13:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .