我想单元测试Play Framework 2.3.7 RESTful api。我正在使用Scala 2.11,Play 2.3.7,slick 3.0,PostgreSql 9.4。我已经为CRUD操作实现了REST api。现在我想对它进行单元测试。
我通过谷歌搜索发现了其中几个。我意识到其中很多都是折旧或已发现已知问题。
那么什么是更新,更容易,推荐的框架?提前谢谢!
答案 0 :(得分:3)
我一直在使用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")
}
}