I followed Scala testing examples using Specs2 from the official Play documentation. I notice that they use WithApplication to run a fake app for testing against, with a clone, as shown below:
"something" should { "do X" in new WithApplication { } "do Y" in new WithApplication { } "do Z" in new WithApplication { } }
That’s good and that’s all, but the problem I am facing is that I take the cost of running my application every time this happens. This is not necessarily “fast” or at least not fast enough once your test suite grows to a reasonable size. I tried doing things like:
val app = FakeApplication() "something" should { "do X" in new WithApplication(app) { } "do Y" in new WithApplication(app) { } "do Z" in new WithApplication(app) { } }
and
"something" should { val app = FakeApplication() Helpers.running(app) { "do X" in { } "do Y" in { } "do Z" in { } } }
The first seems to work for the first test, and then complains about problems connecting to db in subsequent tests. I guess something is closing here or something (not sure what).
The second one does not work at all, because it complains about the lack of a running application, which I am not sure about either.
Any help is appreciated. Thanks!
scala playframework specs2
user131441
source share