Hi,
Considering this method I'd like to test:
public func play(_ soundFileName: String, shouldLoop: Bool) {
Task {
await dataSource.play(soundFileName, shouldLoop: shouldLoop)
}
}
Previously, with XCTest
we could use an expectation and wait for it to be fulfilled:
func test()
sut.play("", shouldLoop: false)
wait(for: [mockedAudioPlayerDataSource.invokedPlayExpectation])
XCTAssertEqual(mockedAudioPlayerDataSource.invokedPlayCount, 1)
With Swift Testing, I am unsure what a unit test looks like.
You code doesn’t include all the details necessary to see exactly what you’re trying to do here, and that make it hard to offer a definitive answer. However, in general, Swift Testing does allow you to test asynchronous code via the Confirmation
type. See Testing asynchronous code.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"