https://github.com/xcessentials/testing
[DEPRECATED - use 'nschum/SwiftHamcrest' instead] A more expressive and readable way to describe expectations in Xcode unit tests.
https://github.com/xcessentials/testing
requirements swift xcode xctest
Last synced: 9 months ago
JSON representation
[DEPRECATED - use 'nschum/SwiftHamcrest' instead] A more expressive and readable way to describe expectations in Xcode unit tests.
- Host: GitHub
- URL: https://github.com/xcessentials/testing
- Owner: XCEssentials
- License: mit
- Created: 2017-03-12T23:30:52.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2019-07-15T18:03:29.000Z (over 6 years ago)
- Last Synced: 2025-06-14T02:04:11.140Z (9 months ago)
- Topics: requirements, swift, xcode, xctest
- Language: Swift
- Homepage:
- Size: 111 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://opensource.org/licenses/MIT)
[](https://cocoapods.org/?q=XCERequirement)
[](https://cocoapods.org/?q=XCERequirement)
[](https://cocoapods.org/?q=XCEUniFlow)
# Problem
Every unit test represents one or several [requirements](https://en.wikipedia.org/wiki/Requirement). Standard Xcode API (XCTest framework) provides very basic expressions that work well, but the result code is not very concise and easy to read/understand.
# Wishlist
1. make the result code concise and self-expressive;
2. allow to express requirement as closure (so it can consist of single value, expression or multiple expressions);
3. allow to return value from a check.
# How to install
The recommended way is to install using [CocoaPods](https://cocoapods.org/?q=XCETesting).
# How it works
The library provides number of helper functions, each of these functions accept requirement description and closure, that returns the value that will be evaluated (and returned for some functions).
# How to use
When you have an `Optional` value or you have a function/closure that produces `Optional` value, and you need this value only if it's NOT `nil`, or call `XCTFail` otherwise:
```swift
let nonNilValue = try RXC.value("Value is NOT nil") {
// return here an optional value,
// it might be result of an expression
// or an optional value captured from the outer scope,
// will call 'XCTFail' if value IS 'nil' or just return
// non-Optional value overwise
}
```
Same as the above, but does not return a anything. When you have an `Optional` value or you have a function/closure that produces `Optional` value, and you need to make sure that this value is NOT `nil`, or call `XCTFail` otherwise:
```swift
try RXC.isNotNil("Value is NOT nil") { // does not return anything
// return here an optional value,
// it might be result of an expression
// or an optional value captured from the outer scope,
// will call 'XCTFail' if value IS 'nil' or pass through
// silently otherwise
}
```
When you have an `Optional` value or you have a function/closure that produces `Optional` value, and you need to make sure that this value IS `nil`, or call `XCTFail` otherwise:
```swift
try RXC.isNil("Value IS nil") { // does not return anything
// return here an optional value,
// it might be result of an expression
// or an optional value captured from the outer scope,
// will call 'XCTFail' if value is NOT 'nil' or pass through
// silently otherwise
}
```
When you have an `Bool` value or you have a function/closure that produces `Bool` value, and you want to continue only if it's `true`, or call `XCTFail` otherwise (if it's `false`):
```swift
try RXC.isTrue("Value is TRUE") { // does not return anything
// return here a boolean value,
// it might be result of an expression
// or an boolean value captured from the outer scope,
// will call 'XCTFail' if value is 'false' or pass through
// silently otherwise
}
```
The `VerificationFailed` data type has the only parameter:
- `let description: String` that contains the requirement description passed to the corresponding `RXC.*` function.