2021 Developer Tools
WWDC21 · 9 min · Developer Tools
Diagnose unreliable code with test repetitions
Test repetitions can help you debug even the most unreliable code. Discover how you can use the maximum repetitions, until failure, and retry on failure testing modes within test plans, Xcode, and xcodebuild to track down bugs and crashers and make your app more stable for everyone. To get the most out of this session, we recommend being familiar with XCTest and managing tests through test plans. For more information, check out “Testing in Xcode” from WWDC19.
Watch at developer.apple.com ↗Code shown on screen · 5 snippets
testFlavors
func testFlavors() {
var truck: IceCreamTruck?
let flavorsExpectation = XCTestExpectation(description: "Get ice cream truck's flavors")
truckDepot.iceCreamTruck { newTruck in
truck = newTruck
newTruck.prepareFlavors { error in
XCTAssertNil(error)
}
flavorsExpectation.fulfill()
}
wait(for: [flavorsExpectation], timeout: 5)
XCTAssertEqual(truck?.flavors, 33)
} testFlavors: add async throws to method header
func testFlavors() async throws {
var truck: IceCreamTruck?
let flavorsExpectation = XCTestExpectation(description: "Get ice cream truck's flavors")
truckDepot.iceCreamTruck { newTruck in
truck = newTruck
newTruck.prepareFlavors { error in
XCTAssertNil(error)
}
flavorsExpectation.fulfill()
}
wait(for: [flavorsExpectation], timeout: 5)
XCTAssertEqual(truck?.flavors, 33)
} testFlavors: use the async version of the ice cream truck
func testFlavors() async throws {
let truck = await truckDepot.iceCreamTruck()
truck = newTruck
newTruck.prepareFlavors { error in
XCTAssertNil(error)
}
flavorsExpectation.fulfill()
}
wait(for: [flavorsExpectation], timeout: 5)
XCTAssertEqual(truck?.flavors, 33)
} testFlavors: use the async version of prepareFlavors
func testFlavors() async throws {
let truck = await truckDepot.iceCreamTruck()
try await truck.prepareFlavors()
XCTAssertEqual(truck?.flavors, 33)
} testFlavors: the truck is no longer optional
func testFlavors() async throws {
let truck = await truckDepot.iceCreamTruck()
try await truck.prepareFlavors()
XCTAssertEqual(truck.flavors, 33)
} Related sessions
-
22 min -
34 min -
12 min -
9 min