Note that there are some explanatory texts on larger screens.

plurals
  1. POtest location provider in android instrumentation test project
    primarykey
    data
    text
    <p>I have an application, which uses the LocationManager. Therefore I'm now writing an instrumentation test. I've found already a similar <a href="https://stackoverflow.com/questions/1972895/testing-gps-in-android/3940877#3940877">answer</a>, but this won't work for me.</p> <pre><code>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()); } } </code></pre> <p>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.</p> <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" package="de.app.android.tests" android:versionCode="1" android:versionName="1.0"&gt; &lt;application&gt; &lt;uses-library android:name="android.test.runner" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" /&gt; &lt;/application&gt; &lt;instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="de.app.android" android:label="Requester App Tests" /&gt; &lt;uses-sdk android:minSdkVersion="4" /&gt; &lt;/manifest&gt; </code></pre> <p>Has somebody an idea how to solve this?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload