所以我有一个函数,其参数是这样的(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]
来获取响应体的字符串值。 - jrudolphFailFastCirceSupport
(1.22.0),entityAs[String]
将无法工作。解决方法是移动导入语句。 - akauppi