【发布时间】:2018-02-17 15:38:51
【问题描述】:
我们有标准目录结构的标准 SBT 项目。
test 文件夹包含所有 JUnit 测试。
我们引入了一个新文件夹 othertests 并且文件夹 othertests 是对等文件夹 测试
othertest 文件夹包含一些特殊的测试用例。 othertest 文件夹中的测试类名称可以很容易地与普通的 JUnit 测试区分开来。
下面是我的工作 build.sbt 配置。
我使用javaSources in Test SBT 任务在测试源中添加了文件夹othertest。
我们正在使用 activator 来运行测试和做其他事情。
当我运行 activator> test 时,我只想运行文件夹 test 中的所有测试,并且我想运行文件夹 othertests 中的测试 分开。
问题。
- 如何覆盖测试任务的行为以从文件夹 othertests 中过滤掉测试
- 我是否应该创建共享模块来分别运行普通的 junit 测试和其他的 junit 测试。
下面是我的 build.sbt 配置
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.")
}
我们在 jenkins 中使用以下命令运行测试 -
bin/activator -Dsbt.log.noformat=true -Denvironment_name=test -DsuppressLogging=true clean silenceSystemErr jacoco:cover
谢谢你 拉克什
【问题讨论】:
标签: scala sbt typesafe-activator