I've been following the Scala testing examples using Specs2 from the official Play documentation. I notice that they use WithApplication
to start up a fake application to test against, with clode like the following:
"something" should {
"do X" in new WithApplication { /* ... */ }
"do Y" in new WithApplication { /* ... */ }
"do Z" in new WithApplication { /* ... */ }
}
This is fine and all, but the problem that I'm having is that I incur the cost of my application starting up each time this happens. This isn't necessarily "fast" or at least not fast enough once your test-suite grows to a reasonable size. I've 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 db connection issues on the later tests. I'm guessing something is getting shutdown here or something (not sure what).
The second doesn't work at all because it complains about there being no running application, which I'm not sure about either.
Any help is greatly appreciated. Thanks!