Xcode Cloud fails to run some of my tests. Looks like it does not recognize the fulfillment(of:timeout:enforceOrder:)
method.
The error I am getting is:
Cannot find 'fulfillment' in scope
The triggering code is very simple and when run locally, all is green. I changed the names of the variables but it looks like this:
func testThatFooThrows() async throws {
// GIVEN
let expectation = expectation(description: "Expect to throw error")
let fooMock = FooMock<Bar>()
fooMock.failWithBadUrlError()
let sut = FooService(contentID: "Test", myService: fooMock)
// WHEN
do {
_ = try await sut.doSomething()
} catch {
expectation.fulfill()
}
// THEN
await fulfillment(of: [expectation], timeout: 0.1)
}
Everything seems to work when I change the failing line to:
wait(for: [expectation], timeout: 0.1)
Instance method 'wait' is unavailable from asynchronous contexts;
Use await fulfillment(of:timeout:enforceOrder:) instead;
this is an error in Swift 6
However, as the warning says, this is not the best.
The documentation says that the fulfillment(of:timeout:enforceOrder:)
method is available starting with Xcode 11. My Xcode Cloud setup uses Xcode 14.3.1 (14E300c)
and macos Ventura 13.5 (22G74)
How can I make Xcode Cloud "see" the fulfillment(of:timeout:enforceOrder:)
method?
It could be an issue with the version of Swift. await fulfillment(_)
is available only from Swift 5.8. So you could try something like this:
#if swift(>=5.8)
await fulfillment(of: [expectation])
#else
wait(for: [expectation])
#endif