Hoa*_*Ong 5 unit-testing scala playframework
我的控制器方法:
def postCategory = Action(parse.tolerantText) { request =>
Ok("")
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试:
val result = categoryController.postCategory.apply(FakeRequest())
status(result) mustEqual OK //error this line
Run Code Online (Sandbox Code Playgroud)
我有这个错误:
错误:(63,14)类型不匹配;找到:play.api.libs.streams.Accumulator [akka.util.ByteString,play.api.mvc.Result]必需:scala.concurrent.Future [play.api.mvc.Result]状态(结果)mustEqual OK ^
似乎使用自定义解析器parse.*使其返回Accumulator而不是Future[Result]
我正在使用play 2.5-RC2
你可以尝试这样的事情:
val result = categoryController.postCategory.apply(FakeRequest())
status(result.run) must equalTo(OK)
Run Code Online (Sandbox Code Playgroud)
基本上看起来 Accumulator 有一个很好的run()方法,可以返回Future.