https://github.com/dfed/swift-testing-expectation
Create an asynchronous expectation in Swift Testing
https://github.com/dfed/swift-testing-expectation
Last synced: 5 months ago
JSON representation
Create an asynchronous expectation in Swift Testing
- Host: GitHub
- URL: https://github.com/dfed/swift-testing-expectation
- Owner: dfed
- License: mit
- Created: 2024-10-20T02:14:36.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-10-21T14:50:19.000Z (6 months ago)
- Last Synced: 2024-10-26T22:50:00.755Z (6 months ago)
- Language: Swift
- Homepage:
- Size: 22.5 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: Contributing.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
- awesome-swift - swift-testing-expectation - Create an asynchronous expectation in Swift Testing. (Libs / Testing)
- fucking-awesome-swift - swift-testing-expectation - Create an asynchronous expectation in Swift Testing. (Libs / Testing)
README
# swift-testing-expectation
[](https://github.com/dfed/swift-testing-expectation/actions?query=workflow%3ACI+branch%3Amain)
[](https://codecov.io/gh/dfed/swift-testing-expectation)
[](https://spdx.org/licenses/MIT.html)
[](https://swiftpackageindex.com/dfed/swift-testing-expectation)
[](https://swiftpackageindex.com/dfed/swift-testing-expectation)Create an asynchronous expectation in Swift Testing
## Testing with asynchronous expectations
The [Swift Testing](https://developer.apple.com/documentation/testing/testing-asynchronous-code) framework vends a [confirmation](https://developer.apple.com/documentation/testing/confirmation(_:expectedcount:isolation:sourcelocation:_:)) method which enables testing asynchronous code. However unlike [XCTest](https://developer.apple.com/documentation/xctest/asynchronous_tests_and_expectations)’s [XCTestExpectation](https://developer.apple.com/documentation/xctest/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:
```swift
@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](https://github.com/apple/swift-package-manager), the following lines can be added to your `Package.swift` file:
```swift
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](http://cocoapods.org), 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](Contributing.md) prior to submitting a Pull Request.