RxBehaviorTester
通过流模式匹配和断言进行Rx行为测试
测试可观察对象
struct State {
var isLoading: Bool
var isSaveEnabled: Bool
var name: String
}
let observable: Observable<State> = ...
let decision = testBehavior(of: observable) { dsl in
dsl.match { $0.isLoading == false }
dsl.assert(.always) { $0.isLoading == false }
dsl.match { $0.name == "Updated Name" }
dsl.match { $0.isSaveEnabled == true }
dsl.run(.async) { triggerSaving() }
dsl.match { $0.isSaveEnabled == false }
}
// Decision will be
// .correct: If no assertions failed and all match clauses matched
// .failed: If any assetions failed or observable completes or times out without matching
匹配器
谓词匹配器
dsl.match { state in
predicate
}
总是断言
dsl.assert(.always) { state in
assertion
}
从定义点开始,在测试完成前检查断言
有界断言
dsl.assert(.untilNextMatch) { state in
assertion
}
仅在匹配器之后的断言处不进行检查时评估断言
无序作用域
dsl.unordered {
dsl... // matchers/assertions or other scopes
}
所有匹配器以任何顺序返回结果时完成
首次作用域
dsl.first {
dsl... // matchers/assertions or other scopes
}
当任何匹配器或断言返回结果(.正确
或.失败
)时完成
要求
- Swift 4.2
- RxSwift 4
安装
RxBehaviorTester 可以通过 CocoaPods 安装。要安装它,只需将以下行添加到您的 Podfile 中
pod 'RxBehaviorTester'
作者
Eliran Ben-Ezra, [email protected]
许可证
RxBehaviorTester受MIT许可证的许可。有关更多信息,请参阅LICENSE文件。