Awesome Open Source
Awesome Open Source


Swift Package Manager Twitter: @johnsundell

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! 🚀

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:

assert(try myFunction(), throwsError: MyError.anError)

That a closure threw a given error:

assertErrorThrown(MyError.anError) {
    try myFunction()

That a closure didn't throw an error:

assertNoErrorThrown {
    try myFunction()

That two objects are the same instance:

assertSameInstance(objectA, objectB)


Swift Package Manager

Add the following dependency to your Package.swift file:

.package(url: "", 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.

Questions or feedback?

Feel free to open an issue, or find me @johnsundell on Twitter.

Get A Weekly Email With Trending Projects For These Topics
No Spam. Unsubscribe easily at any time.
swift (7,337
testing (881
xcode (456
test (190
testing-tools (188
assertions (53
assert (22

Find Open Source By Browsing 7,000 Topics Across 59 Categories