I'm attempting to test the memory and CPU footprint for a SwiftUI iOS app using the following code:
Code Block Swift func testBasicFlowMemory() throws{ let app = XCUIApplication() app.launch() var metrics:[XCTMetric] = [] metrics.append( XCTClockMetric() ) metrics.append( XCTMemoryMetric(application: app) ) metrics.append( XCTCPUMetric(application: app) ) self.measure(metrics: metrics){ /*Method which uses XCUI API to test the app instance*/ self.runBasicFlowTest(app: app) } }
When I run the test above, I notice runBasicFlowTest is executed 6 times (even though the metics only record 5 values.
Of the three metrics I wanted to track only XCTClockMetric returned meaningful data:
XCTMemoryMetric mostly recorded 0.0 or nonsense data:[Clock Monotonic Time, s] values: [114.728229, 114.944770, 121.813337, 116.394432, 117.491242]
XCTCPUMetric likewise recorded 0.0 or nonsense data:[Memory Physical, kB] values: [3596.288000, 0.000000, 0.000000, 0.000000, 0.000000]
[Memory Peak Physical, kB] values: [0.000000, 0.000000, 0.000000, 0.000000, 0.000000]
I'm on Xcode Version 12.4 (12D4e), and my app is targeting iOS 14.4 on a simulated iPhone 11 Pro.[CPU Instructions Retired, kI] values: [0.000000, 206223944.266000, 0.000000, 0.000000, 211895544.471000]
[CPU Cycles, kC] values: [0.000000, 252096240.472000, 0.000000, 0.000000, 257352232.305000],
[CPU Time, s] values: [0.000000, 86.585296, 0.000000, 0.000000, 0.000000]
Has anyone had any luck using XCTMetrics with UI Tests?