Tablier 0.5.2

Tablier 0.5.2

Akkyie 维护。




Tablier 0.5.2

  • 作者
  • Akio Yasui

Tablier

Build Status codecov Swift 5 CocoaPods compatible Carthage compatible SPM compatible Supports iOS, macOS, tvOS and Linux MIT License

A micro-framework for Table Driven Tests.

A screenshot to see how it works

功能

  • ☑️语法简单
  • ☑️并行运行同步和异步测试
  • ☑️除了 XCTest 外没有其他依赖项
  • ☑️Quick 或其他任何基于 XCTest 的测试框架一起使用
  • ☑️完全自我测试

安装

Swift Package Manager

.package(url: "https://github.com/akkyie/Tablier", from: <#version#>)

Cocoapods

target 'YourTests' do
    inherit! :search_paths
    pod 'Tablier'
end

用法

同步配方

您可以为测试类、结构体或函数定义一个 测试配方

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
        })
...

然后,您可以列出配方的输入和预期的输出,以便运行实际的测试。

...
        recipe.assert(with: self) {
            $0.when("1").expect(1)
            $0.when("1234567890").expect(1234567890)
            $0.when("-0x42").expect(-0x42)
        }
    }
}

异步配方

支持定义有异步完成的配方。

let recipe = Recipe<String, Int>(async: { input, complete in
    myComplexAndSlowParse(input) { (result: Int?, error: Error?) in
        complete(result, error)
    }
})

自 Swift 5.5 以来,您可以使用 AsyncRecipe 结合 async/await 语法来定义异步配方。

let recipe = AsyncRecipe<String, Int> { input in
    try await myComplexAndSlowParse(input)
}

注意

注意

当在同步初始化器中抛出错误,或者完成处理程序以错误调用时,当前将测试用例视为失败。预计在将来将支持测试错误。

例子

许可证

麻省理工学院。请参阅LICENSE。