Spray说,任何正常的数据类型,包括Seq,都会自动与JSON进行数据编组。出于某种原因,我没有经历过这种情况。
import spray.json._
import DefaultJsonProtocol._
...
class RestAPITest
extends FlatSpec
with Matchers
with ScalatestRouteTest
with MyRoute
{
...
behavior of "MyRoute"
it should "return a list as JSON" in {
Get("/computers") ~> myRoute ~> check {
status should equal(OK)
// 'sbt test' gives:
// "could not find implicit value for evidence parameter of type spray.httpx.unmarshalling.FromResponseUnmarshaller[Seq[String]]"
//
responseAs[Seq[String]] should contain theSameElementsAs( List( "A01", "A02", "A03", "E01", "G04" ) )
}
}我做错了什么?
发布于 2016-07-31 04:08:55
最后在我的测试类中混合了spray.httpx.SprayJsonSupport特征,以明确所发生的事情。这篇文章简直就是让测试JSON REST API成为本质上的一行程序!高兴的。
http://spray.io/documentation/1.1-SNAPSHOT/spray-httpx/spray-json-support/
感谢@jrudolph :)
https://stackoverflow.com/questions/26507373
复制相似问题