Create an asynchronous expectation in Swift Testing
The Swift Testing framework vends a confirmation method which enables testing asynchronous code. However unlike XCTest’s XCTestExpectation, this confirmation
must be confirmed before the confirmation’s body
completes. Swift Testing has no out-of-the-box way to ensure that an expectation is fulfilled at some indeterminate point in the future.
The Expectation
vended from this library fills that gap:
@Test func testMethodEventuallyTriggersClosure() async {
let expectation = Expectation()
systemUnderTest.closure = { expectation.fulfill() }
systemUnderTest.method()
await expectation.fulfillment(within: .seconds(5))
}
To install swift-testing-expectation in your project with Swift Package Manager, the following lines can be added to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/dfed/swift-testing-expectation", from: "0.1.0"),
]
To install swift-testing-expectation in your project with CocoaPods, add the following to your Podfile
:
pod 'TestingExpectation', '~> 0.1.0'
I’m glad you’re interested in swift-testing-expectation, and I’d love to see where you take it. Please read the contributing guidelines prior to submitting a Pull Request.