test location provider in android instrumentation test project
I have an appl开发者_JAVA技巧ication, which uses the LocationManager. Therefore I'm now writing an instrumentation test. I've found already a similar answer, but this won't work for me.
public class LocationSensorTest extends AndroidTestCase {
/*package*/ LocationManager lm;
private LocationSensor sensor;
@Override
protected void setUp() throws Exception {
super.setUp();
sensor = new LocationSensor(getContext());
lm = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
lm.addTestProvider("test", false, false, false, false, false, false, false, Criteria.POWER_LOW, Criteria.ACCURACY_FINE);
lm.setTestProviderEnabled("test", true);
}
public void testHasAnyActiveLocationProvider() {
assertTrue(sensor.hasAnyActiveLocationProvider());
}
}
The test fails during the "addTestProvider" with a SecurityException that the "android.permission.ACCESS_MOCK_LOCATION" is missing. The Point is that the instrumentation test AndroidManifest.xml has this uses permission, but the application to test not.
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.app.android.tests" android:versionCode="1" android:versionName="1.0">
<application>
<uses-library android:name="android.test.runner" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="de.app.android" android:label="Requester App Tests" />
<uses-sdk android:minSdkVersion="4" />
</manifest>
Has somebody an idea how to solve this?
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
should be outside of <application></application>
精彩评论