MΓ³dulo 16 Β· A Testing Strategy That Scales β LecciΓ³n 3 de 4 Β· ~8 min
Testing async and the network
await works right inside a @Test
Module 13 covered async/await for concurrency; testing it is almost anticlimactic β mark the test function async and await the call under test, same as anywhere else:
@Test func fetchWalkersReturnsResults() async throws {
let client: APIClient = LiveAPIClient()
let walkers = try await client.fetchWalkers()
#expect(!walkers.isEmpty)
}But that test as written has a problem: it hits the real network, through the real LiveAPIClient. Now the test is slow, can fail because a server is down (not because your code is wrong), and needs internet access to run at all in CI.