trait MixedFixtures extends TestSuiteMixin with UnitFixture
Trait that helps you provide different fixtures to different tests: a Application
, a TestServer
, or one
of the Selenium WebDrivers
s.
Trait MixedFixtures
can be mixed into any fixture.Suite
. For convenience it is
mixed into MixedPlaySpec. In a fixture.Suite
, tests can
take a no-arg function. MixedFixtures
provides several no-arg function classes (classes extending Function0
) that
can be used to provide different fixtures for different tests.
If a test needs a Application
, use the App
function, like this:
"provide an Application" in new App(fakeApp("ehcacheplugin" -> "disabled")) { app.configuration.getOptional[String]("ehcacheplugin") mustBe Some("disabled") }
If a test needs an Application
and running TestServer
, use the Server
function, like this:
"send 404 on a bad request" in new Server { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() }
If a test needs an Application
, running TestServer
, and Selenium driver, use
one of functions Chrome
, Firefox
, HtmlUnit
, InternetExplorer
, or Safari
.
If the chosen Selenium driver is unavailable on the host platform, the test will
be automatically canceled. Here's an example that uses the Safari
function:
"provide a web driver" in new Safari(fakeApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } }
Here's a complete example:
package org.scalatestplus.play.examples.mixedfixtures import play.api.test._ import org.scalatestplus.play._ import play.api.{Play, Application} import play.api.inject.guice._ import play.api.routing._ class ExampleSpec extends MixedPlaySpec { // Some helper methods def buildApp[A](elems: (String, String)*) = new GuiceApplicationBuilder() .configure(Map(elems:_*)) .router(TestRoutes.router) .build() def getConfig(key: String)(implicit app: Application) = app.configuration.getOptional[String](key) "The App function" must { "provide an Application" in new App(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getOptional[String]("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new App(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new App(buildApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } } "The Server function" must { "provide an Application" in new Server(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getOptional[String]("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new Server(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new Server(buildApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } import Helpers._ "send 404 on a bad request" in new Server { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } } "The HtmlUnit function" must { "provide an Application" in new HtmlUnit(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getOptional[String]("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new HtmlUnit(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new HtmlUnit(buildApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } import Helpers._ "send 404 on a bad request" in new HtmlUnit { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in new HtmlUnit(buildApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } "The Firefox function" must { "provide an Application" in new Firefox(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getOptional[String]("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new Firefox(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new Firefox(buildApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } import Helpers._ "send 404 on a bad request" in new Firefox { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in new Firefox(buildApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } "The Safari function" must { "provide an Application" in new Safari(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getOptional[String]("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new Safari(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new Safari(buildApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } import Helpers._ "send 404 on a bad request" in new Safari { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in new Safari(buildApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } "The Chrome function" must { "provide an Application" in new Chrome(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getOptional[String]("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new Chrome(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new Chrome(buildApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } import Helpers._ "send 404 on a bad request" in new Chrome { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in new Chrome(buildApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } "The InternetExplorer function" must { "provide an Application" in new InternetExplorer(buildApp("ehcacheplugin" -> "disabled")) { app.configuration.getOptional[String]("ehcacheplugin") mustBe Some("disabled") } "make the Application available implicitly" in new InternetExplorer(buildApp("ehcacheplugin" -> "disabled")) { getConfig("ehcacheplugin") mustBe Some("disabled") } "start the Application" in new InternetExplorer(buildApp("ehcacheplugin" -> "disabled")) { Play.maybeApplication mustBe Some(app) } import Helpers._ "send 404 on a bad request" in new InternetExplorer { import java.net._ val url = new URL("http://localhost:" + port + "/boom") val con = url.openConnection().asInstanceOf[HttpURLConnection] try con.getResponseCode mustBe 404 finally con.disconnect() } "provide a web driver" in new InternetExplorer(buildApp()) { go to ("http://localhost:" + port + "/testing") pageTitle mustBe "Test Page" click on find(name("b")).value eventually { pageTitle mustBe "scalatest" } } } "Any old thing" must { "be doable without much boilerplate" in { () => 1 + 1 mustEqual 2 } } }
- Self Type
- MixedFixtures with TestSuite
- Source
- MixedFixtures.scala
- Alphabetic
- By Inheritance
- MixedFixtures
- UnitFixture
- TestSuiteMixin
- SuiteMixin
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
-
abstract
class
App extends NoArg
NoArg
subclass that provides anApplication
fixture. -
abstract
class
Chrome extends WebBrowser with NoArg with ChromeFactory
NoArg
subclass that provides a fixture composed of anApplication
, runningTestServer
, and SeleniumChromeDriver
. -
abstract
class
Firefox extends WebBrowser with NoArg with FirefoxFactory
NoArg
subclass that provides a fixture composed of aApplication
, runningTestServer
, and SeleniumFirefoxDriver
. -
type
FixtureParam = Unit
- Definition Classes
- UnitFixture
-
abstract
class
HtmlUnit extends WebBrowser with NoArg with HtmlUnitFactory
NoArg
subclass that provides a fixture composed of anApplication
, runningTestServer
, and SeleniumHtmlUnitDriver
. -
abstract
class
InternetExplorer extends WebBrowser with NoArg with InternetExplorerFactory
NoArg
subclass that provides a fixture composed of anApplication
, runningTestServer
, and SeleniumInternetExplorerDriver
. -
abstract
class
Safari extends WebBrowser with NoArg with SafariFactory
NoArg
subclass that provides a fixture composed of anApplication
, runningTestServer
, and SeleniumSafariDriver
. -
abstract
class
Server extends NoArg
NoArg
subclass that provides a fixture composed of aApplication
and runningTestServer
.
Abstract Value Members
-
abstract
def
expectedTestCount(filter: Filter): Int
- Definition Classes
- SuiteMixin
-
abstract
def
nestedSuites: IndexedSeq[Suite]
- Definition Classes
- SuiteMixin
-
abstract
def
rerunner: Option[String]
- Definition Classes
- SuiteMixin
-
abstract
def
run(testName: Option[String], args: Args): Status
- Definition Classes
- SuiteMixin
-
abstract
def
runNestedSuites(args: Args): Status
- Attributes
- protected
- Definition Classes
- SuiteMixin
-
abstract
def
runTest(testName: String, args: Args): Status
- Attributes
- protected
- Definition Classes
- SuiteMixin
-
abstract
def
runTests(testName: Option[String], args: Args): Status
- Attributes
- protected
- Definition Classes
- SuiteMixin
-
abstract
val
styleName: String
- Definition Classes
- SuiteMixin
-
abstract
def
suiteId: String
- Definition Classes
- SuiteMixin
-
abstract
def
suiteName: String
- Definition Classes
- SuiteMixin
-
abstract
def
tags: Map[String, Set[String]]
- Definition Classes
- SuiteMixin
-
abstract
def
testDataFor(testName: String, theConfigMap: ConfigMap): TestData
- Definition Classes
- SuiteMixin
-
abstract
def
testNames: Set[String]
- Definition Classes
- SuiteMixin
-
abstract
def
withFixture(test: (MixedFixtures.this)#NoArgTest): Outcome
- Attributes
- protected
- Definition Classes
- TestSuiteMixin
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @throws( ... )
-
def
withFixture(test: (MixedFixtures.this)#OneArgTest): Outcome
- Definition Classes
- UnitFixture