【发布时间】:2015-11-25 18:08:52
【问题描述】:
所以我有一个带有这个签名的函数(akka.http.model.HttpResponse):
def apply(query: Seq[(String, String)], accept: String): HttpResponse
我只是在如下测试中得到一个值:
val resp = TagAPI(Seq.empty[(String, String)], api.acceptHeader)
我想在类似的测试中检查它的主体:
resp.entity.asString == "tags"
我的问题是如何将响应正文作为字符串获取?
【问题讨论】:
-
你在使用
akka-http-testkit吗?如果是的话,你可以在测试中使用entityAs[String]来获取body作为String值。 -
我需要使用 PlaySpec 所以我不能使用 akka-http-testkit :(
-
我注意到如果将 akka-http-circe 的
FailFastCirceSupport(1.22.0) 带入上下文,entityAs[String]将不起作用。解决方法是移动导入。