AsyncTesting

0.0.7

Testing async code with Swift Concurrency
AsyncSwiftKits/AsyncTesting

What's New

Release 0.0.7

2022-08-22T04:56:52Z

Removes throws from waitForExpectations.

AsyncTesting

Xcode includes XCTest which only has waitForExpectations(timeout:handler:) to support async tests. It does not support waiting on a given list of expectations which is necessary for more complex async activity. The original wait(for:timeout:enforceOrder:) function does take a list of expectations but is not compatible with modern Swift Concurrency.

This package extends XCTestCase to include the asyncExpectation and waitForExpectations functions shown below which mimic existing functions to create and wait on expectations. See the unit tests for more reference code.

let done = asyncExpectation(description: "done")
Task {
    try await Task.sleep(seconds: 0.1)
    await done.fulfill()
}
try await waitForExpectations([done])

Alternatively, the AsyncTesting type can be used to access the same behavior with static functions which may clearly distinguish these functions from native XCTest functions.

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sun Mar 17 2024 17:40:33 GMT-0900 (Hawaii-Aleutian Daylight Time)