Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AndroidManifest.xml for Espresso testing

While running Espresso test with Android studio, I receive an exception while writing to internal storage: java.io.FileNotFoundException: /storage/emulated/0/MyCache: open failed: EACCES (Permission denied)

I do understand that this issue caused by lack of permissions.

My question is, do I have to create additional AndroidManifest file for Espresso test or should I use an existing AndroidManifest file from the app itself? I've tried the 2nd option, but it seems that MainActivityTest is not visible by my app's AndroidManifest.xml

Please refer to attached print screen:

project print screen

like image 717
Alex Kolo Avatar asked Sep 11 '25 12:09

Alex Kolo


2 Answers

It is possible to access application under test (AUT) context by InstrumentationRegistry.getTargetContext(). So if you have declared needed permission in your AUT then you can use it's context.

Other possibility is to save your cache file inside AUT or test application package storage - data/data/com.your.package/files/cache_file. Then you don't need a permission at all.

like image 134
denys Avatar answered Sep 14 '25 01:09

denys


could not understand your question. If your target sdk is marshmallow (sdk 24) so you have to define runtime permissions. Check this out https://developer.android.com/training/permissions/requesting.html

Another solution would be to downgrade the target sdk (try to do this in your build.gradle) or create a new project with target = 23

Share some code so that we could understand the reason of the problem


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!