XCTestBeauty 0.0.1

XCTestBeauty 0.0.1

Hoang Nguyen 维护。



  • 作者:
  • Hoang Nguyen

XCTestBeauty

XCTestBeauty 是一个 Swift 库,提供了一组便利的包装器用于 XCTContext.runActivity()。这些包装器通过允许您在测试活动描述中使用 "GIVEN"、"AND"、"WHEN"、"THEN" 前缀来提高您 XCTest case 的可读性。

安装

您可以使用 CocoaPods 安装 XCTestBeauty。将以下行添加到您的 Podfile

pod 'XCTestBeauty'

然后,运行以下命令

pod install

使用

导入 XCTestBeauty

import XCTestBeauty

用法示例

class YourTestCase: XCTestCase, XCTestBeauty {
    func testExample() {
        given("a precondition") {
            // Your setup code here
        }

        and("an additional condition") {
            // Additional setup code
        }

        when("performing an action") {
            // Your action code here
        }

        then("the expected result should be achieved") {
            // Your assertion code here
        }
    }
}

API文档

givenwhenthen 这些函数是 XCTContext.runActivity() 的包装器,为你的测试案例提供更描述性的结构。它们接受一个描述和一个包含测试活动的闭包。

func given<Result>(_ description: String, _ block: () throws -> Result) rethrows -> Result
func given<Result>(_ description: String, _ block: (XCTActivity) throws -> Result) rethrows -> Result

func and<Result>(_ description: String, _ block: () throws -> Result) rethrows -> Result
func and<Result>(_ description: String, _ block: (XCTActivity) throws -> Result) rethrows -> Result

func when<Result>(_ description: String, _ block: () throws -> Result) rethrows -> Result
func when<Result>(_ description: String, _ block: (XCTActivity) throws -> Result) rethrows -> Result

func then<Result>(_ description: String, _ block: () throws -> Result) rethrows -> Result
func then<Result>(_ description: String, _ block: (XCTActivity) throws -> Result) rethrows -> Result

贡献

如果您发现任何问题或有改进建议,请随时提交问题或拉取请求。

许可证

本库根据MIT许可证发布。有关详细信息,请参阅LICENSE。