我正在实现一个文件存储服务,它获取一个文件并将其保存到具有特殊元数据的 gridFS 中。当然,我想确保一切都在集成中工作——文件确实存储在数据库中,然后从中检索。
我使用 Play Framework 2.1.3 Scala 和 ReactiveMongo 0.9。
我的测试用例如下所示:
"show empty uploaded size on init" in {
running(FakeApplication()) {
Await.result(FileStorage.getFilesSize(profileId), duration) must beNone
}
}
我试图用running
,或所有案例,甚至Thread.sleep
. 但是测试失败后数据库总是启动。
[error] There is no started application
[error] play.api.Play$$anonfun$current$1.apply(Play.scala:51)
[error] play.api.Play$$anonfun$current$1.apply(Play.scala:51)
[error] play.api.Play$.current(Play.scala:51)
[error] content.FileStorage$.db$lzycompute(FileStorage.scala:32)
...
[info] Total for specification FileStorageSpec
[info] Finished in 21 ms
[info] 5 examples, 1 failure, 4 errors
[info]
[info] application - ReactiveMongoPlugin starting...
[info] application - ReactiveMongoPlugin successfully started with db 'test'! Servers:
[localhost:27017]
[info] play - Starting application default Akka system.
[info] play - Shutdown application default Akka system.
我究竟做错了什么?你如何测试 ReactiveMongo 应用程序?