【问题标题】:How can I unit test this Play Scala controller using Specs2?如何使用 Specs2 对这个 Play Scala 控制器进行单元测试?
【发布时间】:2014-04-12 12:21:36
【问题描述】:

我有以下连接到 MongoDB 实例的控制器代码,检索一些数据,然后将数据映射到 JSON 朋友列表,我如何使用 Specs2 对其进行单元测试?

object Friends extends Controller with MongoController {

  def collection: JSONCollection = db.collection[JSONCollection]("friends")

  def list = Action.async {
    val cursor: Cursor[Friend] = collection.find(Json.obj()).cursor[Friend]

    val futureFriendList: Future[List[Friend]] = cursor.collect[List]()

    futureFriendList.map { friends => Ok(Json.toJson(futureFriendList)) }
  }

}

【问题讨论】:

    标签: mongodb scala unit-testing playframework playframework-2.0


    【解决方案1】:

    到目前为止,您做了什么?您可以使用Await.result 从测试中的异步调用中获取值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-11
      • 2013-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多