测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布日期最新发布 | 2017年11月 |
SwiftSwift 版本 | echo "4.0" > .swift-version |
SPM支持 SPM | ✗ |
由 Eduardo Ferreira 维护。
Swift A/B 测试框架,用于 iOS
A/B 测试(也称为拆分测试)是测试新概念的好方法。Gollum 是一个易于使用、灵感来源于 Swift 中一些最佳实践的 A/B 测试框架,例如。
为您的 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
方法可能会抛出 emptyVersionArrayPassed
、selectedVersionNotFound
或 probabilitySumIncorrect
错误。
另外,getSelectedVersion
和 isVersionSelected
方法可能会抛出 selectedVersionNotFound
错误。
由于 Swift 的一些特性,Gollum 不在 Objective-C 中工作。
Gollum 可在 MIT 许可证下获得。有关更多信息,请参阅 LICENSE 文件。