https://github.com/akkyie/tablier
A micro-framework for Table Driven Tests.
https://github.com/akkyie/tablier
parametrized-tests swift swift-package-manager table-driven-test test testing unit-testing xctest
Last synced: 14 days ago
JSON representation
A micro-framework for Table Driven Tests.
- Host: GitHub
- URL: https://github.com/akkyie/tablier
- Owner: akkyie
- License: mit
- Created: 2019-06-02T13:56:01.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2022-08-16T08:31:42.000Z (almost 3 years ago)
- Last Synced: 2024-10-15T00:09:42.486Z (7 months ago)
- Topics: parametrized-tests, swift, swift-package-manager, table-driven-test, test, testing, unit-testing, xctest
- Language: Swift
- Homepage: https://github.com/akkyie/Tablier
- Size: 163 KB
- Stars: 35
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Tablier
[](https://travis-ci.com/akkyie/Tablier)
[](https://codecov.io/gh/akkyie/Tablier)





A micro-framework for [_Table Driven Tests_](https://github.com/golang/go/wiki/TableDrivenTests).

## Features
- ☑️ Dead simple syntax
- ☑️ Run sync and async tests in parallel
- ☑️ No additional dependency aside from XCTest
- ☑️ Use with [Quick](https://github.com/Quick/Quick), or any other XCTest-based testing frameworks
- ☑️ Fully tested itself## Installation
### Swift Package Manager
```swift
.package(url: "https://github.com/akkyie/Tablier", from: <#version#>)
```### Cocoapods
```ruby
target 'YourTests' do
inherit! :search_paths
pod 'Tablier'
end
```## Usage
### Synchronous Recipe
You can define a _test recipe_ to test your classes, structs or functions.
```swift
final class MyParseTests: XCTestCase {
func testMyParse() {
let recipe = Recipe(sync: { input in
// `myParse` here is what you want to test
let output: Int = try myParse(input) // it fails if an error is thrown
return output
})
...
```Then you can list inputs and expected outputs for the recipe, to run the actual test for it.
```swift
...
recipe.assert(with: self) {
$0.when("1").expect(1)
$0.when("1234567890").expect(1234567890)
$0.when("-0x42").expect(-0x42)
}
}
}
```### Asynchronous Recipe
Defining a recipe with an asynchronous completion is also supported.
```swift
let recipe = Recipe(async: { input, complete in
myComplexAndSlowParse(input) { (result: Int?, error: Error?) in
complete(result, error)
}
})
```Since Swift 5.5, you can use `AsyncRecipe` to define asynchronous recipes with async/await syntax:
```swift
let recipe = AsyncRecipe { input in
try await myComplexAndSlowParse(input)
}
```#### Note
> **Note**
>
> When an error is thrown in the sync initalizer or the completion handler is called with an error, the test case is considered as failed for now.
> Testing errors will be supported in the future.## Examples
- [SyncExample.swift](/Examples/Tests/ExampleTests/SyncExample.swift): A simple example with a sync function.
- [AsyncExample.swift](/Examples/Tests/ExampleTests/AsyncExample.swift): An example with an async function.
- [RxTestExample.swift](/Examples/Tests/ExampleTests/RxTestExample.swift): A more real-world-ish example. Test a view model, with RxSwift and RxTest.
- [QuickExample.swift](/Examples/Tests/ExampleTests/QuickExample.swift): An example to show Tablier works in a QuickSpec with no hassle.## License
MIT. See LICENSE.