我想在我的測試類之一注入Configuration實例,我向我的ConfiguredApp測試類和注入配置,它看起來像這樣:如何將配置實例注入scalatest?
@DoNotDiscover()
class MyApiServiceSpec extends FreeSpec with ScalaFutures with ConfiguredApp {
implicit val formats = DefaultFormats
implicit val exec = global
lazy val configuration = app.injector.instanceOf[Configuration]
"Global test" - {
"testcase 1" in {
Server.withRouter() {
case GET(p"/get/data") => Action { request =>
Results.Ok()
}
} { implicit port =>
WsTestClient.withClient { implicit client =>
val service = new MyApiService {
override def config: Configuration = configuration
override val ws: WSClient = client
}
whenReady(service.getData()) { res =>
//i will test stuff here
}
}
}
}
}
}
(MyApiService is a trait)
異常在嵌套套件調用運行時遇到 - ConfiguredApp需要與配置圖中的密鑰 「org.scalatestplus.play.app」關聯的應用程序值。你忘了 用@DoNotDiscover註釋一個嵌套套件嗎? java.lang.IllegalArgumentException:ConfiguredApp需要在配置 映射中與關鍵字「org.scalatestplus.play.app」關聯的應用程序 值。你忘了用@DoNotDiscover註釋一個嵌套套件嗎?
有人有一個想法,爲什麼是...?
感謝!333333
可疑類似:https://stackoverflow.com/questions/39878662/fail-to-inject-configuration-to-scalatest-play-2-5 – rethab