xcode 无法将XCUIDevice的位置设置为nil

3npbholx  于 2023-08-07  发布在  其他
关注(0)|答案(1)|浏览(84)

我的UI测试要求CLLocationManager示例的属性location初始值为nil
因此,在UI测试的方案中,运行选项将默认位置设置为none
UI测试使用

class IPhone_UITestCase: XCTestCase {
    //…
    let device = XCUIDevice.shared
    //…

    override func setUp() {
        super.setUp()
        device.location = nil
        //…
        myApp.launch()
        //…
    }

字符串
而应用程序使用了一个

final class LocationManager: CLLocationManager {
    static let shared = LocationManager()
    //…
}


我期望在我的应用程序推出后,LocationManager.shared.location == nil .
不过,该应用程序是使用location != nil启动的。
原因是什么?

编辑:

将模拟器械位置设置为nil后,在断点处停止UI测试时,会出现以下情况:
Xcode控制台显示UI测试应用程序Resetting the simulated location,与预期一致。
但对于该应用程序,Xcode控制台显示CLLocationManager确实在其代理中调用了locationManager(_:didFailWithError:),错误为The operation couldn’t be completed. (kCLErrorDomain error 0.),并且模拟设备的位置重置。

w3nuxt5m

w3nuxt5m1#

我联系了苹果公司(TSI),得到了答案
...我们相信你的问题可以通过这里链接的Xcode文档来回答:构建
单元测试的位置https://developer.apple.com/documentation/xcode/simulating-location-in-tests#Construct-locations-for-unit-tests
docu说:
...通过将共享XCUIDevice位置设置为XCUILocation的示例来更新模拟设备位置。
显然,这必须解释为不允许(即使可能)将location属性设置为nil,因为nil不是XCUILocation

相关问题