Skip to content

Instantly share code, notes, and snippets.

@ericr3r
Created September 1, 2011 21:53
Show Gist options
  • Save ericr3r/1187393 to your computer and use it in GitHub Desktop.
Save ericr3r/1187393 to your computer and use it in GitHub Desktop.
Web plugin to start Jetty before running Integration Tests
seq(WebIntegrationTests.testSettings :_*)
seq(webSettings :_*)
import sbt._
import Keys._
import WebIntegrationTests._
// project/plugin/WebTestProject
object WebTestProject extends Build
{
lazy val root =
Project("root", file("."))
.configs( WebTest )
.settings( inConfig(WebTest)(Defaults.testSettings) : _*)
.settings( libraryDependencies += scalatest )
lazy val scalatest = "org.scalatest" % "scalatest_2.9.0" % "1.6.1" % "webtest,test"
}
import sbt._
import Keys._
import com.github.siasia.WebPlugin
import WebPlugin._
// project/plugin/WebIntegrationTests
object WebIntegrationTests extends Plugin {
lazy val WebTest = config("webtest") extend(Test)
var state : Option[State] = None
lazy val testSettings: Seq[Project.Setting[_]] = WebPlugin.webSettings ++
inConfig(WebTest) (Defaults.testSettings) ++
Seq (
prepareWebapp <<= (prepareWebapp in Compile).identity,
temporaryWarPath <<= (temporaryWarPath in Compile).identity,
webappResources <<= (webappResources in Compile).identity,
TaskKey[Unit]("test") in WebTest <<= (TaskKey[Unit]("test") in WebTest).dependsOn(prepareWebapp in Compile),
onLoad in Global <<= (onLoad in Global) ?? identity[State],
{
val f = (s: State) => {
state = Some(s)
s
}
onLoad in Global ~= (f compose _)
},
testOptions in WebTest ++= Seq(
Tests.Setup { () =>
if (state.isDefined) {
state = Some(jettyRunAction(state.get))
}
},
Tests.Cleanup { () =>
if (state.isDefined) {
state = Some(withJettyInstance(_.stop())(state.get))
}
}
),
parallelExecution in WebTest := false
)
}
@ericr3r
Copy link
Author

ericr3r commented Sep 1, 2011

Quick plugin that I created for my project to allow the existing web plugin to be used to start jetty before integration tests are run and stop jetty after they have been completed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment