swift-testing-expectation

0.1.4

Create an asynchronous expectation in Swift Testing
dfed/swift-testing-expectation

What's New

0.1.4

2025-05-20T16:13:06Z

What's Changed

  • Stop using CODECOV_TOKEN by @dfed in #9
  • Use executableURL by @dfed in #10
  • Bump linter by @dfed in #14
  • Precondition fulfillment awaited before deinit by @dfed in #13

Full Changelog: 0.1.3...0.1.4

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

Waiting for multiple expectations

The Expectations type vended from this library makes it easy to wait for multiple expectations:

@Test func testMethodEventuallyTriggersClosures() async {
    let expectation1 = Expectation()
    let expectation2 = Expectation()
    let expectation3 = Expectation()

    systemUnderTest.closure1 = { expectation1.fulfill() }
    systemUnderTest.closure2 = { expectation2.fulfill() }
    systemUnderTest.closure3 = { expectation3.fulfill() }
    systemUnderTest.method()

    await Expectations(expectation1, expectation2, expectation3).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.

Description

  • Swift Tools 6.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Wed Jun 04 2025 11:27:47 GMT-0900 (Hawaii-Aleutian Daylight Time)