fncomp
fncomp

Reputation: 6188

How do I change android.permission settings when running tests

Question

I'm working on a third party library that uses geolocation if the 1st party library has provided permissions. I would like to test the behavior, but cannot ship my app w/ the permissions set in the manifest (b/c then it wouldn't be optional).

Is there anyway to set e.g., <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> only while I'm running tests?

Details

I'm using the gradle build tools com.android.tools.build:gradle:0.12.2 and have followed the androidTest directory convention. My project looks like this:

tree src -L 3 src ├── androidTest │   ├── java │   │   └── com │   └── resources └── main ├── AndroidManifest.xml └── java └── com

I tried adding a second manifest in the androidTest folder (I updated the package to be: package="com.myapp.test"), but the geo permissions do not take effect.

I've considered switching to robolectric, but would rather just use the Instrumentation test short term. Please advise if that will make this much easier though.

Upvotes: 4

Views: 873

Answers (1)

elimirks
elimirks

Reputation: 1472

I found a decent solution (not the cleanest IMO):

Add this to your <appname>/build.gradle:

android {
  ...
  sourceSets {
    debug {
      manifest.srcFile 'src/androidTest/AndroidManifest.xml'
    }
  }
  ...
}

And then, of course, create an AndroidManifest.xml file in src/androidTest/ with your required permissions.
I snagged this from the Android issue tracker.

Upvotes: 4

Related Questions