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

Swift:升级到Xcode 10后单元测试方向改变时超时,swift,unit-testing,timeout,orientation,xcode10,Swift,Unit Testing,Timeout,Orientation,Xcode10,我们最近从Xcode 8升级到了10。在最终将所有内容重新编译之后,我在单元测试中遇到了一个涉及方向更改的问题。 我一直在做的模拟设备方向的变化是 XCUIDevice.shared().orientation = .landscapeLeft ... XCUIDevice.shared().orientation = .faceUp ... etc. 现在,当执行这一行时,“设备”(iPhone 8+的模拟器)正在进行适当的方向更改,但由于确认超时,呼

我们最近从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.}

我们最终扩展了KIFSystemTestActor并定义了一个旋转函数:

func rotate(to orientation: UIDeviceOrientation) {
    self.simulateDeviceRotation(to: orientation)
}

这是我根据上面提到的KIF的旋转方法提出的一个扩展

公共扩展XCTestCase{
公用函数等待旋转(到方向:UIInterfaceOrientation){
guard UIApplication.shared.statusBarOrientation!=其他方向{
返回
}
UIDevice.current.setValue(orientation.deviceOrientation.rawValue,forKey:“orientation”)
}
}
然后,在测试用例中,您在开始时调用此方法,以确保方向是您期望的方向

公共函数TestSomeThingInputRait(){ 等待旋转(.肖像) ... }
我也看到了这一点,它阻止了我们转向Xcode 10,因为它破坏了我们的单元测试。这件事能抓住并处理吗?看起来不是这样。而且,在第一次失败后,对景观的后续更改成功,没有出现错误。您能提供一个实现和更多上下文吗?