【问题标题】:Mocking location on map for iOS UI Tests?在地图上模拟 iOS UI 测试的位置?
【发布时间】:2018-09-24 15:10:55
【问题描述】:

那里有人尝试以编程方式在地图上模拟 iOS UI 测试的位置(不使用编辑方案 > 允许位置模拟)吗?

【问题讨论】:

  • 你不知道GPX文件吗?

标签: ios mocking xcuitest testautomationfx


【解决方案1】:

创建协议和模拟位置管理器

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 { }

然后在您的地图视图控制器中:

let locationManager: LocationManager = MockCLLocationManager()

我无法让地图视图以这种方式显示蓝色用户位置指示器。

【讨论】:

    猜你喜欢
    • 2012-02-07
    • 2015-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-15
    • 1970-01-01
    相关资源
    最近更新 更多