Mocking location on map for iOS UI Tests?

324 views Asked by At

anyone out there tried mocking location on map for iOS UI Tests programmatically (not using edit scheme > allow location simulation) please?

1

There are 1 answers

0
Kacper Cz On

Create a protocol and mock location manager

import CoreLocation

protocol LocationManager: class {
    var location: CLLocation? { get }
}

final class MockCLLocationManager: LocationManager {
    var location: CLLocation? {
        return CLLocation(latitude: CLLocationDegrees(exactly: 52.51657052665494)!,
                          longitude: CLLocationDegrees(exactly: 13.381044881575008)!)
    }
}

extension CLLocationManager: LocationManager { }

Then in your map view controller:

let locationManager: LocationManager = MockCLLocationManager()

I can't get the map view to display the blue user location indicator this way though.