我将一些Akka HTTP代码的同步ScalaTest测试切换到AsyncFunSpec。有没有简单的方法让Akka TestKit测试也是异步的呢?我说的代码是这样的:
Get("/test") ~> testRoute ~> check {
responseAs[String] shouldEqual "Fragments of imagination"
}我基本上需要的是一个版本的check,它返回一个Future,而不是调用await。或者是一个帮助器函数,它将Get("/test")之类的HttpRequest转换为RequestContext,这样我就可以将路由应用于它。
发布于 2017-08-22 22:50:45
我最终使用了这样的东西:
import akka.http.scaladsl.client.RequestBuilding.Get
import akka.http.scaladsl.server.Route
val handler = Route.asyncHandler(testRoute)
for {
response <- handler(Get("/test"))
strict <- response.entity.toStrict
res <- strict.toString shouldEqual "Fragments of imagination"
} yield reshttps://stackoverflow.com/questions/45671574
复制相似问题