Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dfed/swift-testing-expectation
Create an asynchronous expectation in Swift Testing
https://github.com/dfed/swift-testing-expectation
Last synced: 4 days 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 (25 days ago)
- Default Branch: main
- Last Pushed: 2024-10-21T14:50:19.000Z (24 days ago)
- Last Synced: 2024-10-26T22:50:00.755Z (18 days 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
README
# swift-testing-expectation
[![CI Status](https://img.shields.io/github/actions/workflow/status/dfed/swift-testing-expectation/ci.yml?branch=main)](https://github.com/dfed/swift-testing-expectation/actions?query=workflow%3ACI+branch%3Amain)
[![codecov](https://codecov.io/gh/dfed/swift-testing-expectation/branch/main/graph/badge.svg?token=nZBHcZZ63F)](https://codecov.io/gh/dfed/swift-testing-expectation)
[![License](https://img.shields.io/badge/License-MIT-blue.svg)](https://spdx.org/licenses/MIT.html)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fdfed%2Fswift-testing-expectation%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/dfed/swift-testing-expectation)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2Fdfed%2Fswift-testing-expectation%2Fbadge%3Ftype%3Dplatforms)](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.