ios - 如何更改 XCTest for iOS 测试的方向?

标签 ios objective-c xctest xctestcase

我正在尝试使用 XCTestCase 在不同方向测试我的 iOS 应用程序。我需要一种以编程方式改变方向的方法。我尝试用两种方法进行此操作,但都没有改变方向(方向保持为 UIInterfaceOrientationPortrait)。

尝试 1

[UIApplication sharedApplication].statusBarOrientation = UIInterfaceOrientationLandscapeLeft;`

尝试 2

[[UIDevice currentDevice] setValue:[NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft] forKey:@"orientation"];`

当我阅读 [[UIApplication sharedApplication] statusBarOrientation] 是否有另一种方法可以更改方向以进行测试?

最佳答案

快速代码:

XCUIDevice.shared.orientation = UIDeviceOrientation.portrait;

关于ios - 如何更改 XCTest for iOS 测试的方向?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35634182/

相关文章:

ios - 在 swift 2 和 xcode 7 beta 4 中设置谷歌分析时出错

iOS 项目 : Static/Dynamic code analysis and call graphs

ios - "C Compiler not working"构建时尝试在 iOS 中构建 VLC

unit-testing - 如何获得可以抛出我正在使用 XCTAssertNoThrow(...) 测试的函数的返回值

ios - XCUITest 与通知横幅交互。

objective-c - NSStream 处理事件给出状态 4

ios - 用于 UITextfield setLeftView 的 xcode UIView ScaleAspectFit

objective-c - 将 mac osx 应用程序转换为 ios 应用程序的最简单方法

ios - 打开相机时截取屏幕截图 -iOS

iOS - 如何对深层链接进行单元测试以确保它们可以在应用程序端进行处理