【发布时间】:2020-09-19 07:26:33
【问题描述】:
使用Play 2.7。在一个测试类中,我想测试一个读取配置(属性)文件conf/fun.conf的服务。
我找不到任何如何执行此壮举的示例。我查看了 Play 文档以及此处的问题,但一无所获。
我写的服务通过注入得到Configuration:
class MyFunService @Inject() (config: Configuration) extends FunService {
override def getValue(key: String) = config.get[String](key)
}
我想通过测试调用此服务:
class FunSpec(implicit ee: ExecutionEnv) extends Specification {
sequential
"The FunService" should {
"retrieve a value" in new WithApplication() {
//Oops! Does not actually read the conf file...
val env = play.api.Environment.simple()
val config = play.api.Configuration.load(env)
//...so getting an Exception here.
val f = Future(new MyFunService(config).getValue("fun_stuff"))
f must beEqualTo("having_fun").await(retries = 0, timeout = 5.seconds)
}
}
}
【问题讨论】:
标签: scala playframework specs2