Gollum 0.4.0

Gollum 0.4.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布日期最新发布2017年11月
SwiftSwift 版本echo "4.0" > .swift-version
SPM支持 SPM

Eduardo Ferreira 维护。



Gollum 0.4.0

Gollum

Swift A/B 测试框架,用于 iOS

codecov.io Code Climate

A/B 测试(也称为拆分测试)是测试新概念的好方法。Gollum 是一个易于使用、灵感来源于 Swift 中一些最佳实践的 A/B 测试框架,例如。

  • 值类型(结构体和枚举)
  • 错误处理(ErrorType 和 throws)
  • 编译时反馈

用法

为您的 A/B 测试创建一个带有 Version 类型的 enum。在每个情况中传递一个包含版本名称(例如 a)及其概率(例如 0.5)的字符串,两者均由 : 分隔。

enum MyABTest: Version {
    case a = "A:0.5"
    case b = "B:0.5"
}

在 Gollum 中注册测试案例

try Gollum.instance.registerVersions([MyABTest.a, MyABTest.b])

注册后,您可以使用 getSelectedVersion 检查选择了哪个版本

switch try Gollum.instance.getSelectedVersion(MyABTest.self) {
case .a:
    view.backgroundColor = UIColor.red
case .b:
    view.backgroundColor = UIColor.green
}

或使用 isVersionSelected

if try Gollum.instance.isVersionSelected(MyABTest.a) {
    view.backgroundColor = UIColor.red
} else if try Gollum.instance.isVersionSelected(MyABTest.b) {
    view.backgroundColor = UIColor.green
}

错误处理

为了在 A/B 测试中避免不可预期的场景,处理错误非常重要。Gollum 可以抛出以下错误

public enum GollumError: Error {
    case versionSyntaxError(String)
    case probabilitySumIncorrect(String)
    case emptyVersionArrayPassed(String)
    case selectedVersionNotFound(String)
}

如果创建了一个带有错误语法(例如缺少版本名称或概率)的 A/B 测试枚举,则应用将崩溃并显示错误 versionSyntaxError

enum MyABTest: Version {
    case a = ":0.5"
    case b = "B:0.5"
}

错误信息

fatal error: 'try!' expression unexpectedly raised an error: Gollum.GollumError.versionSyntaxError("ABTest case expression must have name and probability values splitted by : (e.g. \"MyTestCaseA:0.5\")")

在 A/B 测试注册期间,registerVersions 方法可能会抛出 emptyVersionArrayPassedselectedVersionNotFoundprobabilitySumIncorrect 错误。

另外,getSelectedVersionisVersionSelected 方法可能会抛出 selectedVersionNotFound 错误。

Objective-C

由于 Swift 的一些特性,Gollum 不在 Objective-C 中工作。

许可证

Gollum 可在 MIT 许可证下获得。有关更多信息,请参阅 LICENSE 文件。