Unit test gps functionality

I have a Android app which uses gps for various functionality.
How do i unit test the gps?
And can it be done without running a device?




  • YkshLeoYkshLeo USMember ✭✭✭✭
    edited February 2016

    You can try something like this :

    public class GPSPollingServiceTest
        LocationManager locationManager;
        public void TestGPS()
            Context context;
            var locationManager = context.GetSystemService (Context.LocationService) as LocationManager;
            locationManager.AddTestProvider ("Test", false, false, false, false, false, false, false, Power.Low, Android.Hardware.SensorStatus.AccuracyHigh);
            locationManager.SetTestProviderEnabled("Test", true);
            // Set up your test
            var location = new Location("Test");
            location.Latitude = 10.0;
            location.Longitude = 20.0;
            locationManager.SetTestProviderLocation("Test", location);
            // Check if your event reacted the right way

    For this to work you also need a required permission to the AndroidManifest.xml:

    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />

    Refer :

  • JakobJensenJakobJensen DKMember ✭✭

    What kind of project do i need to be able to use the GMS?

Sign In or Register to comment.