Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mochidev/XCTAsync
Swift library to more easily test async code
https://github.com/mochidev/XCTAsync
swift swift-concurrency swift-package-manager xctest
Last synced: 3 months ago
JSON representation
Swift library to more easily test async code
- Host: GitHub
- URL: https://github.com/mochidev/XCTAsync
- Owner: mochidev
- License: mit
- Created: 2022-09-05T23:59:35.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2022-09-06T16:07:40.000Z (about 2 years ago)
- Last Synced: 2024-07-24T08:43:18.340Z (3 months ago)
- Topics: swift, swift-concurrency, swift-package-manager, xctest
- Language: Swift
- Homepage:
- Size: 6.84 KB
- Stars: 34
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# XCTAsync
`XCTAsync` redefines many `XCTAssert` functions as async functions within asynchronous contexts.
## Installation
Add `XCTAsync` as a dependency in your `Package.swift` file to start using it. Then, add `import XCTAssert` to any file you wish to use the library in.
Please check the [releases](https://github.com/mochidev/XCTAsync/releases) for recommended versions.
```swift
dependencies: [
.package(url: "https://github.com/mochidev/XCTAsync.git", .upToNextMajor(from: "1.0.0")),
],
...
targets: [
.testTarget(
name: "MyPackageTests",
dependencies: [
"XCTAsync",
]
)
]
```## What is `XCTAsync`?
`XCTAsync` is a collection of functions for testing asynchonous code:
```swift
import XCTest
import XCTAsyncfunc testAsyncMethods() async {
await XCTAssertTrue(await asynchronousMethod())
}
```Note that `XCTAsync` is only necessary for async methods, and will not be overloaded in synchronous contexts:
```swift
import XCTest
import XCTAsyncfunc testSyncMethods() {
XCTAssertTrue(synchronousMethod())
}
```However, if you are in an asynchronous test, you'll need to use the asynchronous variants for each assert:
```swift
import XCTest
import XCTAsyncfunc testSyncMethods() async {
await XCTAssertTrue(synchronousMethod())
}
```## Contributing
Contribution is welcome! Please take a look at the issues already available, or start a new issue to discuss a new feature. Although guarantees can't be made regarding feature requests, PRs that fit with the goals of the project and that have been discussed before hand are more than welcome!
Please make sure that all submissions have clean commit histories, are well documented, and thoroughly tested. **Please rebase your PR** before submission rather than merge in `main`. Linear histories are required.