Implicit method that returns the Application instance for the current test.
Implicit method that returns the Application instance for the current test.
Creates new instance of Application with parameters set to their defaults.
Creates new instance of Application with parameters set to their defaults. Override this method if you
need an Application created with non-default parameter values.
The port used by the TestServer.
The port used by the TestServer. By default this will be set to the result returned from
Helpers.testServerPort. You can override this to provide a different port number.
Implicit PortNumber instance that wraps port.
Implicit PortNumber instance that wraps port. The value returned from portNumber.value
will be same as the value of port.
the configured port number, wrapped in a PortNumber
Creates new Application and running TestServer instances before executing each test, and
ensures they are cleaned up after the test completes.
Creates new Application and running TestServer instances before executing each test, and
ensures they are cleaned up after the test completes. You can access the Application from
your tests as app and the TestServer's port number as port.
the no-arg test function to run with a fixture
the Outcome of the test execution
Trait that provides a new
Applicationand runningTestServerinstance for each test executed in a ScalaTestSuite.This
TestSuiteMixintrait overrides ScalaTest'swithFixturemethod to create a newApplicationandTestServerbefore each test, and ensure they are cleaned up after the test has completed. TheApplicationis available (implicitly) from methodapp. TheTestServer's port number is available asport(and implicitly available asportNumber, wrapped in a PortNumber).By default, this trait creates a new
Applicationfor each test using default parameter values, which is returned by thenewAppForTestmethod defined in this trait. If your tests need anApplicationwith non-default parameters, overridenewAppForTestto return it.Here's an example that demonstrates some of the services provided by this trait:
package org.scalatestplus.play.examples.oneserverpertest import play.api.test._ import org.scalatest._ import org.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ import play.api.routing._ class ExampleSpec extends PlaySpec with OneServerPerTest { // Override newAppForTest or use GuiceOneServerPerTest implicit override def newAppForTest(testData: TestData): Application = new GuiceApplicationBuilder() .configure(Map("ehcacheplugin" -> "disabled")) .router(Router.from(TestRoute)) .build() "The OneServerPerTest trait" must { "provide a FakeApplication" in { app.configuration.getString("ehcacheplugin") mustBe Some("disabled") } "make the FakeApplication available implicitly" in { def getConfig(key: String)(implicit app: Application) = app.configuration.getString(key) getConfig("ehcacheplugin") mustBe Some("disabled") } "start the FakeApplication" in { Play.maybeApplication mustBe Some(app) } "provide the port number" in { port mustBe Helpers.testServerPort } "provide an actual running server" in { import Helpers._ import java.net._ val url = new URL("http://localhost:" + port + "/boum") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } } }