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! 🚀
Here is what you can currently assert using the functions that Assert
provides:
assert(try myFunction(), throwsError: MyError.anError)
assertErrorThrown(MyError.anError) {
try myFunction()
}
assertNoErrorThrown {
try myFunction()
}
assertSameInstance(objectA, objectB)
Add the following dependency
to your Package.swift
file:
.package(url: "https://github.com/johnsundell/assert", from: "1.0.0")
Then, you can import Assert
in your tests, like this:
import Assert
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.
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.
Feel free to open an issue, or find me @johnsundell on Twitter.