I have this performance test to check Memory usage during scrolling.
func testMemotyUsage() {
let app = XCUIApplication()
let measureOptions = XCTMeasureOptions()
measureOptions.invocationOptions = [.manuallyStop]
measure(
metrics: [XCTMemoryMetric(application: app)],
options: measureOptions
) {
app.buttons["Listing Page"].tap()
swipeUp()
stopMeasuring()
tapBack()
}
}
func tapBack() {
app.navigationBars.buttons.element(boundBy: 0).tap()
}
func swipeUp() {
collectionView.swipeUp(velocity: .fast)
}
func swipeDown() {
collectionView.swipeDown(velocity: .fast)
}
var collectionView: XCUIElement {
app.collectionViews["collectionViewId"]
}
But when I run the test, it doesn't display any metrics at all.
I tried to update
XCTMemoryMetric(application: app)
-> to XCTMemoryMetric()
In this case it at least shows some result, but the result is incorrect, because as it's seen on the screenshot below, the app consumes around 130 MB of memory, but the test shows 9 KB only. BTW the real memory consumption is around 130-150 MB, because there are a lot of images in the collection view.
My guess that it doesn't show the correct result, because the app
is not passed as a parameter. Although when I pass the app
, it doesn't show any results at all 🙃
Same issue happens when I write the test to check CPU usage with XCTCPUMetric
.
Questions:
-
How to write a performance test that will show memory and CPU usage of some UI tests?
-
(Optional) Why when I run the test in Debug mode, it shows that 2 processes are running (
ExampleUITests
- the target for UI tests, andExample
- the main target). Is it normal and when I measure the memory consumption, am I supposed to get the consumption of the main targetExample
, right?