Reputation: 6582
I'm using Play Framework 2.1.x and would like to have two test configs one for small tests and the other one for large tests. The large test needs to have custom javaOptions value. I have the following config, however it seems that the javaOptions setting does not get picked up.
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val mySettings = Seq(...)
val smallTestSettings = Defaults.testSettings ++ Seq(
testOptions := Seq(Tests.Filter(smallTests))
)
val largeTestSettings = Defaults.testSettings ++ Seq(
testOptions := Seq(Tests.Filter(largeTests)),
javaOptions ++= Seq("-Dmysetting=1") // <--- PROBLEM HERE
)
lazy val SmallTest = config("smalltest") extend(Test)
lazy val LargeTest = config("largetest") extend(Test)
val main = play.Project(appName, appVersion, appDependencies)
.configs(SmallTest)
.configs(LargeTest)
.settings(mySettings: _*)
.settings(inConfig(SmallTest)(smallTestSettings): _*)
.settings(inConfig(LargeTest)(largeTestSettings): _*)
}
Interestingly, if I change the line to:
javaOptions in Test ++= Seq("-Dmysetting=1")
then it does get picked up by both the large and small tests. Any ideas on how I can set this custom javaOptions only for the large test config?
Upvotes: 4
Views: 795
Reputation: 7542
val largeTestSettings = Defaults.testSettings ++ Seq(
testOptions := Seq(Tests.Filter(largeTests)),
testOptions in LargeTest += Tests.Argument("-Dmysetting=1")
)
I got the specs2 tests only to read the properties, if they are annotated with the JUnitRunner:
import org.junit.runner.RunWith
import org.specs2.mutable.Specification
import org.specs2.runner.JUnitRunner
@RunWith(classOf[JUnitRunner])
class LargeScalaTest extends Specification {
"mysetting should be 1" in {
System.getProperty("mysetting") must beEqualTo("1")
}
}
My test project is in a branch on GitHub.
Upvotes: 1