I have introduced a method that works so far. I would like Play to introduce the concept of individual areas of "Test" vs "IntegrationTest" in sbt.
I could go to Play and see how they build their project and settings in sbt and try to get the IntegrationTest scope. Right now, I spent too much time trying to make it function.
What I did was create a Specs Around Scope class that gives me the ability to enforce a single TestServer instance. Everything that the class uses will try to start the test server, if it is already running, it will not restart.
It seems that Play and SBT are doing their best to keep the server shut down when the test finishes, and it still works.
Here is a sample code. Still looking forward to more feedback.
class WithTestServer(val app: FakeApplication = FakeApplication(), val port: Int = Helpers.testServerPort) extends Around with Scope { implicit def implicitApp = app implicit def implicitPort: Port = port synchronized { if ( !WithTestServer.isRunning ) { WithTestServer.start(app, port) } } // Implements around an example override def around[T: AsResult](t: => T): org.specs2.execute.Result = { println("Running test with test server===================") AsResult(t) } } object WithTestServer { var singletonTestServer: TestServer = null var isRunning = false def start(app: FakeApplication = FakeApplication(), port: Int = Helpers.testServerPort) = { implicit def implicitApp = app implicit def implicitPort: Port = port singletonTestServer = TestServer(port, app) singletonTestServer.start() isRunning = true } }
To do this further, I simply configure two folders (packages) in the play / test folder: - test / block (test.unit package) - test / integration (test.integration pacakage)
Now that I am running from my Jenkins server, I can run:
play test-only test.unit. * Spec
This will perform all unit tests.
To run my integration tests, I run:
play test-only test.integration. * Spec
What is it. This works for me until Play adds an integration test as a life cycle step.