2020 Developer Tools
WWDC20 · 14 min · Developer Tools
Eliminate animation hitches with XCTest
Animations can dramatically enhance the user experience of your app, provide a sense of direct manipulation, and help people to better understand the results of their actions. Animation hitches can break that experience. Discover how to use XCTest to detect interruptions to smooth scrolling and animations, and learn how to catch regressions before they affect the people relying on your app.
Watch at developer.apple.com ↗Code shown on screen · 4 snippets
Create an animation os_signpost interval
os_signpost(.animationBegin, log: logHandle, name: "performAnimationInterval")
os_signpost(.end, log: logHandle, name: "performAnimationInterval") Use a UIKit instrumented animation os_signpost interval
extension XCTOSSignpostMetric {
open class var navigationTransitionMetric: XCTMetric { get }
open class var customNavigationTransitionMetric: XCTMetric { get }
open class var scrollDecelerationMetric: XCTMetric { get }
open class var scrollDraggingMetric: XCTMetric { get }
} Measure scrolling animation performance using a Performance XCTest
// Measure scrolling animation performance using a Performance XCTest
func testScrollingAnimationPerformance() throws {
app.launch()
app.staticTexts["Meal Planner"].tap()
let foodCollection = app.collectionViews.firstMatch
measure(metrics: [XCTOSSignpostMetric.scrollDecelerationMetric]) {
foodCollection.swipeUp(velocity: .fast)
}
} Reset the application state between runs
func testScrollingAnimationPerformance() throws {
app.launch()
app.staticTexts["Meal Planner"].tap()
let foodCollection = app.collectionViews.firstMatch
let measureOptions = XCTMeasureOptions()
measureOptions.invocationOptions = [.manuallyStop]
measure(metrics: [XCTOSSignpostMetric.scrollDecelerationMetric],
options: measureOptions) {
foodCollection.swipeUp(velocity: .fast)
stopMeasuring()
foodCollection.swipeDown(velocity: .fast)
}
} Related sessions
-
24 min -
15 min -
11 min -
14 min -
7 min -
12 min -
13 min