https://github.com/johnsundell/assert
A collection of convenient assertions for Swift testing
https://github.com/johnsundell/assert
assert assertions swift test testing testing-tools xcode
Last synced: 7 months ago
JSON representation
A collection of convenient assertions for Swift testing
- Host: GitHub
- URL: https://github.com/johnsundell/assert
- Owner: JohnSundell
- License: mit
- Created: 2017-02-20T18:31:57.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-11-05T22:30:32.000Z (almost 8 years ago)
- Last Synced: 2025-03-18T05:34:58.756Z (7 months ago)
- Topics: assert, assertions, swift, test, testing, testing-tools, xcode
- Language: Swift
- Size: 50.8 KB
- Stars: 68
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
![]()
This repo contains a collection of assertion functions that you can use in your tests, as a complement to the assertions provided by `XCTest`, or other testing frameworks. This collection will likely grow over time, and you are more than welcome to contribute your own custom assertion functions as a pull request! :rocket:
## What's in the box?
Here is what you can currently assert using the functions that `Assert` provides:
#### That an expression threw a given error:
```swift
assert(try myFunction(), throwsError: MyError.anError)
```#### That a closure threw a given error:
```swift
assertErrorThrown(MyError.anError) {
try myFunction()
}
```#### That a closure didn't throw an error:
```swift
assertNoErrorThrown {
try myFunction()
}
```#### That two objects are the same instance:
```swift
assertSameInstance(objectA, objectB)
```## Usage
#### Swift Package Manager
Add the following `dependency` to your `Package.swift` file:
```swift
.package(url: "https://github.com/johnsundell/assert", from: "1.0.0")
```Then, you can import `Assert` in your tests, like this:
```swift
import Assert
```#### Manually
You can also simply clone the repo, and drag the file `Sources/Assert.swift` into your Xcode project and add it to your test target.
## Contributing
To work on `Assert` in Xcode, first generate an Xcode project through the Swift Package Manager:
```
$ swift package generate-xcodeproj
```Then, make your changes to `Assert.swift`, and submit a pull request with your changes.
## Questions or feedback?
Feel free to [open an issue](https://github.com/JohnSundell/Assert/issues/new), or find me [@johnsundell on Twitter](https://twitter.com/johnsundell).