ScalaTest - 如何找出最终块中的方法执行了多少次?
ScalaTest - how can I find out how many times a method inside an eventually block was executed?
我正在使用 ScalaTest 的 Eventually.eventually
并将其配置为每秒尝试获取一条记录,直到状态完成:
Eventually.eventually(timeout(5 seconds), interval(1 seconds)) {
getItem(recordId).record.forall(
_.state.contains(Constants.RecordStatusComplete)) shouldEqual true
}
我必须得到 getItem(recordId)
被调用的次数。我该怎么做?
数一数怎么样?可能有点难看,但 scalatest 似乎没有向您提供它所做的尝试次数,大概这只是为了测试,所以:
val count = Iterator from 0
Eventually.eventually(timeout(5 seconds), interval(1 seconds)) {
count.next()
getItem(recordId).record.forall(
_.state.contains(Constants.RecordStatusComplete)) shouldEqual true
}
// count.next() will give you the attempts
我可以想到使用模拟框架等的其他解决方案,但结果可能非常相似。
我正在使用 ScalaTest 的 Eventually.eventually
并将其配置为每秒尝试获取一条记录,直到状态完成:
Eventually.eventually(timeout(5 seconds), interval(1 seconds)) {
getItem(recordId).record.forall(
_.state.contains(Constants.RecordStatusComplete)) shouldEqual true
}
我必须得到 getItem(recordId)
被调用的次数。我该怎么做?
数一数怎么样?可能有点难看,但 scalatest 似乎没有向您提供它所做的尝试次数,大概这只是为了测试,所以:
val count = Iterator from 0
Eventually.eventually(timeout(5 seconds), interval(1 seconds)) {
count.next()
getItem(recordId).record.forall(
_.state.contains(Constants.RecordStatusComplete)) shouldEqual true
}
// count.next() will give you the attempts
我可以想到使用模拟框架等的其他解决方案,但结果可能非常相似。