KeyPathTesting
Context
KeyPathTesting is a Swift framework that leverages Result Builders to implement a new syntax that allows developers to write KeyPath-based unit tests.
Here's an example of how it can be used:
class MyTests: XCTestCase {
func test() {
let myData = [1, 2, 3, 4]
assert(on: myData) {
\.isEmpty == false
\.count > 2
\.first == 1
\.last != 1
}
}
}
How does it work?
I've made a video to explain in details the internal implementation of KeyPathTesting
Requirements
Xcode 12.5 & Swift 5.4
Installation
SPM
Package.swift
Add a new dependency to your package by adding the following to Package.swift
:
.package(url: "https://github.com/vincent-pradeilles/KeyPathTesting", from: "0.0.1"),
Xcode
Open your project file in the project navigator and select the project instead of one of your targets. Switch to the Swift Packages tab and click the plus.
When prompted enter the url https://github.com/vincent-pradeilles/KeyPathTesting
CocoaPods
Add the following to your Podfile
:
pod "KeyPathTesting"
Carthage
Add the following to your Cartfile
:
github "vincent-pradeilles/KeyPathTesting" == 0.1.4
Please note that newer versions of this framework do not officially support Carthage anymore
Author
- Vincent Pradeilles: @v_pradeilles
Contributors
- Henrik Panhans: @henrik_dmg