【发布时间】:2015-12-28 19:56:23
【问题描述】:
我目前正在测试一个 akka 应用程序。
我遇到了某种模式:我想测试TestProbe 是否收到了某个消息,以某些字段为模。
例如,如果消息是:
UserInfo(username: String, score: Int, timestamp: String)
然后我可能想测试username 和score 是否符合预期,但不在乎何时收到消息。
目前我想写这样的东西:
testProbe.expectMsgPF() {
case UserInfo(`username`, `score`, _) =>
}
如何扩展测试探针类,以便编写类似的东西?
testProbe.expectApproxMsg(UserInfo(`username`, `score`, _))
除了缩短我的代码之外,我希望这个问题的答案能加深我对 Scala 编程语言的理解。
【问题讨论】:
标签: scala unit-testing akka akka-testkit testkit