Override this function to instantiate the components - a factory of sorts.
Override this function to instantiate the components - a factory of sorts.
the components to be used by the application
Implicit method that returns the Application instance for the current test.
Implicit method that returns the Application instance for the current test.
a context to use to create the application.
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.
new application instance and set the components. This must be called for components to be properly set up.
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
An extension of BaseOneServerPerTest providing Compile-time DI.
Trait that provides a new
Applicationand runningTestServerinstance for each test executed in a ScalaTestSuiteThis
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 according to the components defined in the test.Here's an example that demonstrates some of the services provided by this trait:
import org.scalatestplus.play.PlaySpec import org.scalatestplus.play.components.OneServerPerTestWithComponents import play.api._ import play.api.mvc.Result import play.api.test.Helpers._ import play.api.test.{FakeRequest, Helpers} import scala.concurrent.Future class ExampleComponentsSpec extends PlaySpec with OneServerPerTestWithComponents { override def components: BuiltInComponents = new BuiltInComponentsFromContext(context) with NoHttpFiltersComponents { import play.api.mvc.Results import play.api.routing.Router import play.api.routing.sird._ lazy val router: Router = Router.from({ case GET(p"/") => defaultActionBuilder { Results.Ok("success!") } }) override lazy val configuration: Configuration = context.initialConfiguration ++ Configuration("foo" -> "bar", "ehcacheplugin" -> "disabled") } "The OneServerPerTestWithComponents trait" must { "provide an Application" in { import play.api.test.Helpers.{GET, route} val Some(result): Option[Future[Result]] = route(app, FakeRequest(GET, "/")) Helpers.contentAsString(result) must be("success!") } "override the configuration" in { app.configuration.getOptional[String]("foo") mustBe Some("bar") } } }