Integration test in the Play Framework

I am trying to get integration tests to work in Play Framework 2.1.1

My goal is to run integration tests after unit tests to test the functionality of the component level with the database. Procedures will be stored in the base database, so it is very important that I can do more than just "inMemoryDatabase", which you can configure in the Fake Application.

I would like this process to be as follows:

  • Launch TestServer with FakeApplication. Use Alternate Integration Test Test File
  • Run integration tests (can be filtered by packages or not)
  • Stop TestServer

I believe the best way to do this is in the Build.scala file.

I need help on how to configure the Build.scala file, as well as how to download the alternative integration test configuration file (project / it.conf right now)

Any help is much appreciated!

+4
source share
1 answer

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.

+5
source

All Articles