【发布时间】:2016-05-28 10:34:29
【问题描述】:
使用 scalatest 运行测试时,我不时收到 IllegalStateException:
future 返回了一个异常类型: java.lang.IllegalStateException,带有消息:无法初始化 执行上下文; AsyncExecutor 已经关闭。
我将 ScalaTest 2.2.6 与 Play framework 2.4 和 Slick 3.1 结合使用。测试如下:
class FooDaoImplSpec
extends PlaySpec
with TestConfiguration
with OneAppPerSuite
with ScalaFutures
with IntegrationPatience {
override lazy val app = new GuiceApplicationBuilder()
.loadConfig(testConfig)
.in(Mode.Test)
.bindings(bind[FooDao].to[FooDaoImpl])
.build
"FooDao#findAll" must {
"return a result set with the length of 3" in {
val fooDao = app.injector.instanceOf[FooDao]
val result: Future[Seq[FooModel]] = fooDao.findAll()
whenReady(result) { r =>
r must have length (3)
}
}
}
}
fooDao 在上面的例子中使用 Slick 来查询数据库。也许还值得一提的是,FooDaoImpl 使用了 Play 的内部执行上下文 (play.api.libs.concurrent.Execution.Implicits.defaultContext)。
我真的有点卡在这里。正如我已经提到的,异常是在我的一个测试套件中随机抛出的,但只是偶尔抛出。
以前有没有人遇到过同样的问题?任何帮助表示赞赏。
【问题讨论】:
标签: playframework playframework-2.0 slick scalatest slick-3.0