Lightweight addition of useful assertions to XCTest
I've been using these assertions in different projects for a while and they proved quite handy, so I decided to move them to separate package. It is important that this package only contains the actual assertions without extra noise, to make it small and easy to add.
-
Add
swifty-test-assertions
to package dependencies inPackage.swift
:.package(url: "git@github.com:artem-y/swifty-test-assertions.git", from: "0.1.1"),
-
Add
SwiftyTestAssertions
product dependency to test target(s) inPackage.swift
:.product(name: "SwiftyTestAssertions", package: "swifty-test-assertions"),
-
Import
SwiftyTestAssertions
module where they need to be used:import SwiftyTestAssertions
-
Go to File > Add Package Dependencies... in Xcode top navigation menu.
- or go to project settings "Package Dependencies" and hit "+"
- or go to "General" target settings tab, in target's "Frameworks and Settings" section choose "+", then select "Add Package Dependency..."
-
Search for
artem-y/swifty-test-assertions
(paste this link into search):git@github.com:artem-y/swifty-test-assertions.git
-
When Xcode finds the package, select "Up to Next Major Version" dependency rule and press "Add Package" button
-
Choose a test target that needs to use this package and press "Add Package"
-
Import
SwiftyTestAssertions
module where they need to be used:import SwiftyTestAssertions
Assert(
try sut.validate(colorHex: "ABCXYZ"), // tested expression
throwsError: ArgumentValidator.ColorHexError.hasInvalidSymbols // check if this exact error is thrown
)
More code examples using these helpers can be found in examples-of-swifty-test-assertions repository. They are kept there separately to make this library as lightweight as possible.