iPhone 的頻率是 60 hz,平均每一幀的時間是 16.67 ms,當 APP 中的幀時間佔用大於 16.67 ms 時就會形成視覺上的卡頓。markdown
func testScrollingAnimationPerformance() throws {
// step1
let app = XCUIApplication()
app.launch()
app.staticTexts["Meal Planner"].tap()
let foodCollection = app.collectionViews.firstMatch
// step2
let meausreOptions = XCTMeasureOptions()
meausreOptions.invocationOptions = [.manuallyStop]
// step3
measure(metrics: [XCTOSSignpostMetric.scrollDraggingMetric],
options: meausreOptions) {
// 向上滑動
foodCollection.swipeUp(velocity: .fast)
// 中止測試
stopMeasuring()
// 向下滑動
foodCollection.swipeDown(velocity: .fast)
}
}
複製代碼
代碼說明app
添加手動中止、中止測試、向下滑動的代碼重置環境,是由於要保證每次測試的環境是一致的,這樣的測試結果纔會相對正確。post
XCTOSSignpostMetric 可測試的指標測試