Async/await and XCTest

I have the same pain points. For example you cannot use XCTUnwrap() on an async function.

Additionally when I try to build tests in a docker container with image swiftlang/swift:nightly-5.5-focal, I get errors such as this:

/build/.build/x86_64-unknown-linux-gnu/debug/my-async-project-serverPackageTests.derived/AppTests.swift:109:29: error: invalid conversion from 'async' function of type '() async throws -> ()' to synchronous function type '() throws -> Void' testCase(BasicAsyncTests.__allTests__BasicAsyncTests),


I gave up waiting and rewrote all my tests.

It looks like this PR to swift-corelibs-xctest would add async tests to Swift for Linux. So you can write tests such as

func testFetchSomething() async throws {
   let fetchResult = try! await fetchSomething()

@jonprescott can you prove that? what stops me from building my own toolchain with custom XCTest? Won't it work?

As long as you stay out of the Xcode environment. XCTest is provided as private frameworks and plugins within Xcode, and it supports all the languages that Xcode supports (C/C++/Obj-C/Obj-C++/Swift), not just Swift.

If you are writing for Linux, Windows, etc., shouldn't have a problem.

Terms of Service

Privacy Policy

Cookie Policy