首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从Spray response测试JSON数组?

如何从Spray response测试JSON数组?
EN

Stack Overflow用户
提问于 2014-10-22 20:23:58
回答 1查看 1.2K关注 0票数 4

Spray说,任何正常的数据类型,包括Seq,都会自动与JSON进行数据编组。出于某种原因,我没有经历过这种情况。

代码语言:javascript
复制
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" ) )
    }
  }

我做错了什么?

EN

回答 1

Stack Overflow用户

发布于 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 :)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26507373

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档