Appboy / appboy-android-sdk

Public repo for the Braze Android SDK
https://www.braze.com
Other
153 stars 102 forks source link

Does Braze use Context.getSharedPreferences under the hood in Braze.changeUser? #232

Closed alvindizon closed 2 years ago

alvindizon commented 2 years ago

What problem are you facing?

Our app is currently using Braze SDK v21.0.0, and the recent updates to the Braze SDK have broken our unit tests. We basically have a wrapper class that stores a reference to a Braze object, and it is thru this wrapper that we log custom events, change users, etc.

We use MockK for unit tests and in one of our unit tests, we ran into this error: can't find stub Context(temporary mock) when testing our class that calls Braze.changeUser. Looking at the stack trace of the error, it seems to point to getSharedPreferences:

    at app//android.content.Context$Subclass2.getSharedPreferences(Unknown Source)
    at app//bo.app.e.a(SourceFile:10)
    at app//bo.app.e.getBoolean(SourceFile:1)
    at app//bo.app.v4.a(SourceFile:1)
    at app//com.braze.Braze$Companion.isDisabled(SourceFile:12)
    at app//com.braze.Braze.run$android_sdk_base_release(SourceFile:1)
    at app//com.braze.Braze.run$android_sdk_base_release$default(SourceFile:1)
    at app//com.braze.Braze.changeUser(SourceFile:2)
    at app//com.braze.Braze.changeUser(SourceFile:1)
    at app//com.someapp.analytics.BrazeWrapper.changeUser(BrazeWrapper..kt:20)

Could you enlighten us or provide advice on how to resolve this?

Workarounds

N/A

Ideal Solution

No response

Other Information

No response

radixdev commented 2 years ago

All Braze methods on the singleton can use sharedpreferences in order to accomplish the various actions of the SDK. In order to assist with your mocking, the SDK retrieves its application context via applicationContext = context.applicationContext where context is the one passed into the getInstance() method.

radixdev commented 2 years ago

Hey @alvindizon ,

I'm closing this issue for now. Please let me know if you continue to have issues and we'll debug further.