We have standard SBT project with standard directory structure.
The test folder contains all the JUnit tests.
We introduced a new folder othertests and the folder othertests is peer to folder test
The othertest folder contains some special test cases. The test classes names in the folder othertest can be easily distinguished from the normal JUnit tests.
Below is my working build.sbt configuration.
I have added the folder othertest in test sources using javaSources in Test
SBT task.
We are using activator to run tests and do other stuff.
When I run activator> test
I want all tests from the folder test only to run and I want to run tests from the folder othertests separately.
Questions.
- How to override the behavior of test tasks to filter out tests from the folder othertests
- Should I create shared modules to run normal junit tests separately and other junit tests separately.
Below is my build.sbt configuration
import java.io.PrintStream
import play.sbt.PlayJava
import play.twirl.sbt.Import._
name := "Service"
version := "5.1.0"
scalaVersion := "2.11.8"
routesGenerator := InjectedRoutesGenerator
lazy val ContractTest = config("contract") extend(Test)
def contractTestFilter(name: String): Boolean = name endsWith "ContractTest"
def ignoreContractTest(name: String): Boolean = !contractTestFilter(name)
lazy val root = (project in file("."))
.enablePlugins(PlayJava)
.configs(ContractTest)
.settings(
inConfig(ContractTest) (Defaults.testTasks),
javaSource in Test := { (baseDirectory in Test) (_ / "contracttest") }.value,
testOptions in ContractTest := Seq(Tests.Filter(contractTestFilter),Tests.Argument(TestFrameworks.JUnit, "-q", "-v", "-s")),
testOptions in Test := Seq(Tests.Filter(ignoreContractTest),Tests.Argument(TestFrameworks.JUnit, "-q", "-v", "-s"))
)
lazy val xyz = taskKey[Unit]("custom task to create loglayout jar file under lib folder")
xyz := {
LogLayoutJar.build(scalaBinaryVersion.value, streams.value.log)
}
run := (run in Runtime).dependsOn(xyz).evaluated
javaOptions in Test ++= Seq("-Dconfig.resource=applic.tt.cnf")
libraryDependencies ++= Seq(
json,
javaWs,
"org.mockito" % "mockito-all" % "1.10.19" % Test,
"org.scalatestplus.play" %% "scalatestplus-play" % "1.5.1" % Test,
"org.easytesting" % "fest-assert" % "1.4" % Test,
"org.scalactic" %% "scalactic" % "2.2.0",
"org.jmockit" % "jmockit" % "1.9" % Test,
"com.portingle" % "slf4jtesting" % "1.0.0" % Test,
"org.scalacheck" %% "scalacheck" % "1.12.6" % Test
)
resolvers ++= Seq(
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
)
parallelExecution in Test := runningTestInParallel
testGrouping in Test := groupByModule((externalDependencyClasspath in Test).value,
(definedTests in Test).value, streams.value.log)
javacOptions ++= Seq(
"-Xlint:unchecked",
"-Xlint:deprecation"
)
scalacOptions ++= Seq(
"-feature",
"-language:implicitConversions",
"-deprecation"
)
// Custom tasks //
val silenceSystemErr = taskKey[Unit]("Replaces System.err with a PrintStream to nowhere.")
silenceSystemErr := {
System.setErr(new PrintStream(new DevNull))
println("Messages System.err will not be printed.")
}
val restoreSystemErr = taskKey[Unit]("Restores the original System.err")
restoreSystemErr := {
System.setErr(systemErr)
println("Messages System.err will be printed.")
}
From jenkins we run tests using below command -
bin/activator -Dsbt.log.noformat=true -Denvironment_name=test -DsuppressLogging=true clean silenceSystemErr jacoco:cover
Thank You Rakesh