【问题标题】:What is recommended library for unit testing Playframework 2.3.7 RESTful api [closed]什么是单元测试 Playframework 2.3.7 RESTful api 的推荐库 [关闭]
【发布时间】:2015-03-04 12:16:02
【问题描述】:
我想对 Play Framework 2.3.7 RESTful api 进行单元测试。我正在使用 Scala 2.11、Play 2.3.7、slick 3.0、PostgreSql 9.4。我已经为 CRUD 操作实现了 REST api。现在我想对其进行单元测试。
我通过谷歌搜索找到了其中的几个。我意识到其中许多已被贬值或发现已知问题。
那么有什么更新、更简单、推荐的框架可用?提前致谢!
【问题讨论】:
标签:
postgresql
scala
rest
unit-testing
slick
【解决方案1】:
我一直在使用 JUnit 和规范测试我的 Play Rest 服务。
import org.junit.runner._
import org.specs2.mutable._
import org.specs2.runner._
import play.api.libs.json._
import play.api.test.Helpers._
import play.api.test._
@RunWith(classOf[JUnitRunner])
class TestAddressController extends Specification {
"Address Controller" should {
"make findAll request" in new WithApplication {
val request = route(FakeRequest(GET, "/address")).get
status(request) must equalTo(OK)
contentType(request) must beSome.which(_ == "application/json")
}
}