【发布时间】:2018-01-10 04:16:48
【问题描述】:
我想为我的 playframework scala 应用程序编写测试。
我的测试是这样的:
class ProcessInstancesControllerSpec extends PlaySpecification {
sequential
"ProcessInstancesController" should {
def ProcessInstancesController(implicit app: Application) = {
val app2ProcessInstancesController = Application.instanceCache[controllers.ProcessInstancesController]
app2ProcessInstancesController(app)
}
implicit val projectInstanceFormat = Json.format[ProcessInstancesModel]
val validProcessInstanceJson = AnyContentAsJson(Json.parse(
"""{
| "processTemplateId":47,
| "startedAt":"2017-12-19 13:50:24",
| "updatedAt":"2017-12-19 13:50:24",
| "status":"started",
| "comment":"",
| "deleted":false,
| "clientId":35,
| "steps":[
| {
| "id":62,
| "title":"Scala Test",
| "createdat":"2017-12-12 11:09:56.0",
| "updatedat":"2017-12-12 11:09:56.0",
| "deadline":1512946800000,
| "stepType":1,
| "position":0,
| "deleted":false,
| "processTemplate_id":47,
| }
| ]
|}""".stripMargin))
val app = GuiceApplicationBuilder().overrides(bind[DeadboltHandler].to[DeadboltHandlerMock])
"respond to the index Action" in new WithApplication {
val Some(result) = route(app, FakeRequest(GET, "/processInstanceAll/35"))
status(result) must equalTo(OK)
contentType(result) must beSome("text/html")
charset(result) must beSome("utf-8")
contentAsString(result) must contain("[{\"data\":{\"id\":117")
contentAsString(result) must contain("processTemplateId")
contentAsString(result) must contain("clientId")
// contentAsString(result) must contain("Hello Bob")
}
当我尝试运行它时,我收到了以下错误消息:
java.lang.NoSuchMethodError: Fatal execution error, caused by play.api.inject.guice.GuiceApplicationBuilder$.apply$default$9()Lscala/Option;
java.lang.NoSuchMethodError: play.api.inject.guice.GuiceApplicationBuilder$.apply$default$9()Lscala/Option;
at play.api.test.WithApplication$.$lessinit$greater$default$1(Specs.scala:36)
at controllers.ProcessInstancesControllerSpec$$anonfun$2$$anonfun$apply$2$$anon$1.<init>(ProcessInstancesControllerSpec.scala:108)
第 108 行是"respond to the index Action" in new WithApplication {
在这种情况下可能会出现什么问题?
提前致谢。
更新:
我将第 108 行更改为 "respond to the index Action" in new WithApplication(app.build) {
现在我收到了这个错误:
java.lang.AbstractMethodError: Fatal execution error, caused by play.api.libs.logback.LogbackLoggerConfigurator.configure(Lplay/api/Environment;Lplay/api/Configuration;Lscala/collection/immutable/Map;)V
更新:
如果我这样做:
val app = GuiceApplicationBuilder().overrides(bind[DeadboltHandler].to[DeadboltHandlerMock]).build
"respond to the index Action" in new WithApplication(app) {
我收到了这个错误:
InvocationTargetException for 'main' in org.specs2.NotifierRunner: null
【问题讨论】:
标签: scala unit-testing playframework