How to Test Swift async/await Code With XCTest
Because async/await is a feature at the Swift language level, to test an
async
function we can use the same approach we’d use to consume that code in production: call it withawait
.[…]
To appreciate how neater this is than the approach we used before the introduction of
async await
, let me show you the same test but for achopVegetables
version using callbacks andResult
.[…]
Unfortunately the
XCTAssertThrowsError
and the other assertion APIs don’t support concurrency yet, sodo catch
is the only option to test the error path ofasync
code.