Home

Awesome

swift-testing-expectation

CI Status codecov License

Create an asynchronous expectation in Swift Testing

Testing with asynchronous expectations

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))
}

Installation

Swift Package Manager

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"),
]

CocoaPods

To install swift-testing-expectation in your project with CocoaPods, add the following to your Podfile:

pod 'TestingExpectation', '~> 0.1.0'

Contributing

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.