Appboy / appboy-android-sdk

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

[Bug]: Unable to pass Mocked context to Braze.getInstance(context: Context) while writing unit test case. Showing, "Braze cannot be returned by getApplicationContext" #241

Closed gitanshubatra239 closed 1 year ago

gitanshubatra239 commented 1 year ago

Braze Android SDK Version

23.1.1

Steps To Reproduce

Write some unit test case related to braze that internally requires call to Braze.getInstance(context). Mock the call Braze.getInstance(context) with the mocked context.

Expected Behavior

When passing mocked context to Braze.getInstance(mockedContext) , It should work correct and return a Braze instance.

Actual Incorrect Behavior

While Passing mocked context, It is showing an error : "Braze cannot be returned by getApplicationContext()"

Verbose Logs

No response

Additional Information

No response

radixdev commented 1 year ago

Hi @gitanshubatra239 ,

  1. This seems like a bug in your testing framework.
  2. The Braze instance cannot be instantiated in production use cases with a mocked context.
  3. (Try ensuring that your mock returns a context for getApplicationContext() since we call that internally) 👍🏽
gitanshubatra239 commented 1 year ago

Does Braze.getInstance() using getBrazeLogTag() internally? As, it is causing me issues while mocking Braze.getInstance()