Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

https://github.com/q231950/rorschach

Write XCTests in BDD style 🤷🏻‍♂️
https://github.com/q231950/rorschach

bdd bdd-style swift-function-builders swift-result-builders testing uitest unittest xctest

Last synced: about 1 month ago
JSON representation

Write XCTests in BDD style 🤷🏻‍♂️

Lists

README

        

The Rorschach Logo

**This package allows you to write XCTest tests in a BDD style.**

Similar to Swift Regex and SwiftUI it's Swift's result builders that allow for a lightweight DSL that can make your tests way more readable.

Take a look at the following example:

```swift
func test_simple_example() {

let universe = UniverseContext()

expect {
Given("I have a universe without any stars") {
universe.numberOfStars = 0
}
When("I add a couple of stars") {
universe.numberOfStars = 23
}
Then("I can see the stars I have added ✨") {
XCTAssertEqual(universe.numberOfStars, 23)
}
}
}
```

Please note that the contents of each [Step](Sources/Rorschach/Step.swift) like `universe.numberOfStars = 23` for example, are arbitrary Swift code - you are free to add your abstractions on a Page Object Model or the like as you need them.

The test run leads to this result in Xcode's Report Navigator. An easy to read output that can easily be understood in case of a failure.

Corresponding test result in Xcode's Report Navigator

Corresponding test result with failure in Xcode's Report Navigator

---

Contributions are much appreciated. Any kind of feedback about whether or not this is helpful for you or if you want to share ways to improve _Rorschach_ are highly welcome. Reach out on Twitter to [q231950](https://twitter.com/q231950) or [create a new issue](https://github.com/q231950/rorschach/issues/new).