gpt4 book ai didi

unit-testing - Play 2.2 - specs2 - 如何在 play 2.2 中测试 future ?

转载 作者:行者123 更新时间:2023-12-04 10:07:52 26 4
gpt4 key购买 nike

我测试 future 的方法是使用 value1。
我迁移到play2.2。我发现,我习惯的测试方式已经一去不复返了。
@scala.deprecated("使用 scala.concurrent.Promise 代替。", "2.2")

任何帮助将不胜感激。

奥利弗

最佳答案

您可以按照 documentation 中的描述实现 PlaySpecification 特征。 .这个 trait 提供了一个方法 await。您还可以覆盖默认超时。

import akka.util.Timeout
import scala.concurrent.duration._

class FooSpec extends PlaySpecification {
override implicit def defaultAwaitTimeout: Timeout = 20.seconds

"foo" should {
"handle futures" {
val result = await(Future(true))

result should beTrue
}
}
}

关于unit-testing - Play 2.2 - specs2 - 如何在 play 2.2 中测试 future ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19131963/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com