I have a Play Framework 2.3 project in which I'd like to separate unit tests and functional tests as follows:
- running
sbt test
should run unit tests and exclude integration tests - running
sbt it:test
should run integration tests only
The Scala documentation suggests using project/Build.scala
, but I'd like to use combination of build.sbt
and project/Build.scala
, so my configuration looks like this (I have also tried putting all of configuration into Build.scala
):
build.sbt
....
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-json" % "2.2.3",
"org.scalatest" %% "scalatest" % "2.1.5" % "it, test",
"org.mockito" % "mockito-all" % "1.9.5" % "it, test"
)
def funTestFilter(name: String): Boolean = ((name endsWith "ItTest") || (name endsWith "IntegrationTest"))
def unitTestFilter(name: String): Boolean = ((name endsWith "Test") && !funTestFilter(name))
testOptions in IntegrationTest := Seq(Tests.Filter(funTestFilter))
testOptions in Test := Seq(Tests.Filter(unitTestFilter))
project/Build.scala
import sbt._
object Build extends Build {
lazy val root =
Project("root", file("."))
.configs( IntegrationTest )
.settings( Defaults.itSettings : _* )
}
Under this configuration running sbt test
does exclude my integration test (which ends with IntegrationTest
) but running sbt it:test
finds no tests.
The article suggests putting files in a specific path, but I don't know what the equivalent path is for the Play project.
The standard source hierarchy is used:
src/it/scala for Scala sources
src/it/java for Java sources
src/it/resources for resources that should go on the integration test classpath