final class SutTest: XCTestCase {
var sut: Sut!
override func setUp() {
super.setUp()
sut = Sut()
}
override func tearDown() {
sut = nil
super.tearDown()
}
func testExample() {
let clockMetric = XCTClockMetric()
let start = XCTPerformanceMeasurementTimestamp()
measure(metrics: [clockMetric]) {
sut.testing()
}
let end = XCTPerformanceMeasurementTimestamp()
let array = try! clockMetric.reportMeasurements(from: start, to: end)
array.count // array is empty
}
}
I want to pull out metrics information, found this method reportMeasurements. But when I try to get it, nothing happens.
I want to get the report that shows in xcode but i want to access it in code. I want to get the average value of the code passage time. How can I get information about metrics in the code?


The
reportMeasurementsmethod returns anarray of XCTClockMeasurement objects. EachXCTClockMeasurementobject represents a single measurement of time. TheXCTClockMeasurement objecthas aduration propertythat represents the amount of time that was measured.averageDurationvariable will contain the average amount of time that was spent executing thesut.testing()method.