Monday, 14 September 2020

getExternalFilesDir(null) returns null in Espresso tests

I'm trying to access getExternalFilesDir(null) from an Espresso test during the execution of a @BeforeClass method to set up some app files before starting tests.

I'm trying to access it like this: InstrumentationRegistry.getInstrumentation().context.getExternalFilesDir(null)

Environment.getExternalStorageState() returns "mounted", yet getExternalFilesDir(null) returns null in the above call, contrary to the documentation which states it would only return null if storage wasn't mounted.

Interestingly enough, InstrumentationRegistry.getInstrumentation().context.filesDir does return a value, but it returns a non-existent folder which is under a test package instead of the app's actual package.

How can I access and write to app's scoped storage when setting up an Espresso test?



from getExternalFilesDir(null) returns null in Espresso tests

No comments:

Post a Comment