Art*_*nko 17 objective-c ios xctest xcode7 uitest
从Xcode 7开始,我们有一个很好的用于UI测试的API.大多数情况下我对它很满意.唯一的问题与速度有关.
在一开始,普通的UI测试用例(大约15个动作)运行大约25秒.然后我完全嘲笑网络.现在需要20秒.考虑到时间只取决于动画和启动时间(1秒甚至更短),我想,必须有办法加快速度.
Mar*_*ark 26
在UI测试运行时尝试设置此属性:
UIApplication.shared.keyWindow?.layer.speed = 100
Run Code Online (Sandbox Code Playgroud)
这是我如何设置它:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if ProcessInfo.processInfo.arguments.contains("UITests") {
UIApplication.shared.keyWindow?.layer.speed = 100
}
}
Run Code Online (Sandbox Code Playgroud)
在我的UI测试中:
class MyAppUITests: XCTestCase {
// MARK: - SetUp / TearDown
override func setUp() {
super.setUp()
let app = XCUIApplication()
app.launchArguments = ["UITests"]
app.launch()
}
}
Run Code Online (Sandbox Code Playgroud)
这篇博客文章中有一些方便的提示.
另一种可能性是禁用动画:
[UIView setAnimationsEnabled:NO];
Run Code Online (Sandbox Code Playgroud)
斯威夫特3:
UIView.setAnimationsEnabled(false)
Run Code Online (Sandbox Code Playgroud)
在@Mark 回答之后,Swift 3版本:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
if ProcessInfo.processInfo.arguments.contains("UITests") {
UIApplication.shared.keyWindow?.layer.speed = 200
}
}
Run Code Online (Sandbox Code Playgroud)
在你的 ui 测试文件上:
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
let app = XCUIApplication()
app.launchArguments = ["UITests"]
app.launch()
Run Code Online (Sandbox Code Playgroud)