A micro-framework for Table Driven Tests.
- ☑️ Dead simple syntax
- ☑️ Run sync and async tests in parallel
- ☑️ No additional dependency aside from XCTest
- ☑️ Use with Quick, or any other XCTest-based testing frameworks
- ☑️ Fully tested itself
.package(url: "https://github.com/akkyie/Tablier", from: <#version#>)
target 'YourTests' do
inherit! :search_paths
pod 'Tablier'
end
You can define a test recipe to test your classes, structs or functions.
final class MyParseTests: XCTestCase {
func testMyParse() {
let recipe = Recipe<String, Int>(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.
...
recipe.assert(with: self) {
$0.when("1").expect(1)
$0.when("1234567890").expect(1234567890)
$0.when("-0x42").expect(-0x42)
}
}
}
Defining a recipe with an asynchronous completion is also supported.
let recipe = Recipe<String, Int>(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:
let recipe = AsyncRecipe<String, Int> { input in
try await myComplexAndSlowParse(input)
}
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.
- SyncExample.swift: A simple example with a sync function.
- AsyncExample.swift: An example with an async function.
- RxTestExample.swift: A more real-world-ish example. Test a view model, with RxSwift and RxTest.
- QuickExample.swift: An example to show Tablier works in a QuickSpec with no hassle.
MIT. See LICENSE.