Running the tests described here
"Spec" should { "example" in new WithApplication { ... } }
unacceptably slower for me. This is because the new WithApplication method starts and stops the structure in each example. Do not get me wrong, the platform itself loads very quickly, but if the database is configured (surprise!), The situation becomes terrible.
Here are some measurements:
"The database layer" should { "test1" in { 1 must be equalTo(1) } ... "test20" in { 1 must be equalTo(1) } }
Runtime: 2 seconds . The same test with WithApplication in each example takes 9 seconds.
I was able to achieve much better results thanks to this answer.
import play.api.Play import play.api.test.FakeApplication import org.specs2.mutable.Specification import scalikejdbc._ class MySpec extends Specification { var fake: FakeApplication = _ step {fake = FakeApplication(...)} step {Play.start(fake)} "The database layer" should { "some db test" in { DB localTx { implicit session => ... } } "another db test" in { DB localTx { implicit session => ... } } step {Play.stop()} }
}
Pros: increased productivity
Minuses:
you need to copy-paste the settings and disrupt the code, because you donβt know how to reuse (reuse I mean something like "class MySpec extends Specification with NoWasteOfTime "
new WithApplication () calls Helpers.running, which looks like this
synchronized { try { Play.start(fakeApp) block } finally { Play.stop() play.api.libs.ws.WS.resetClient() } }
therefore, I cannot fully emulate the behavior of Helpers.running (resetClient is not displayed for my code) without reflection.
Please suggest how to break down the cons or another approach, how to solve my problem.
Jeriho
source share