gpt4 book ai didi

Swift:升级到 Xcode 10 后单元测试方向发生变化时超时

转载 作者:搜寻专家 更新时间:2023-10-31 22:54:19 25 4
gpt4 key购买 nike

我们最近从 Xcode 8 升级到 10。在 - 最终 - 再次编译所有内容之后,我在涉及方向更改的单元测试中遇到了问题。我一直在做的模拟设备方向变化是

    XCUIDevice.shared().orientation = .landscapeLeft
...
XCUIDevice.shared().orientation = .faceUp
...
etc.

现在,当执行此行时,“设备”(iPhone 8+ 的模拟器)正在进行适当的方向更改,但由于确认超时,调用最终失败了:

    [iMomTests.DataScreenTests testLandscape] : Failed to set orientation: Error Domain=XCTDaemonErrorDomain Code=15 "Timed out waiting for confirmation of orientation change." UserInfo={NSLocalizedDescription=Timed out waiting for confirmation of orientation change.}

最佳答案

这是我根据上面提到的KIF的旋转方式想出来的扩展。

public extension XCTestCase {
public func waitUntilRotation(to orientation: UIInterfaceOrientation) {
guard UIApplication.shared.statusBarOrientation != orientation else {
return
}
UIDevice.current.setValue(orientation.deviceOrientation.rawValue, forKey:"orientation")
}
}

然后,在测试用例中,您在开始时调用此方法以确保方向符合您的预期。

public func testSomethingInPortrait() {
waitUntilRotation(.portrait)
...
}

关于Swift:升级到 Xcode 10 后单元测试方向发生变化时超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52426297/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com