问题
Below is my Build.scala file
There is no error in test, but the cleanup hook is not executed after test
what is the issue?
import play.Project._
import sbt._
import sbt.Keys._
object AppBuild extends Build {
val appName = "test"
val appVersion = "1.0"
val dependencies = Seq(
"org.scalatest" % "scalatest_2.10" % "2.0.RC1"
)
val main = play.Project(
appName, appVersion,
dependencies,
settings = Defaults.defaultSettings
)
.settings(
scalaVersion := "2.10.1",
testOptions in Test += Tests.Cleanup (
() => println("Cleanup")
)
)
}
回答1:
testOptions in Test += Tests.Cleanup
does not work with forked test runs as mentioned in another Stackoverflow answer.
But there are workarounds:
Set fork to false
This is simple but may slow down your tests because they won't be executed in parallel.
sbt.Keys.fork in Test := false
Use the test framework
For example http://doc.scalatest.org/1.9.2/index.html#org.scalatest.BeforeAndAfterAll with the protected method afterAll()
Override the test task
My favorite.
test in Test ~= { testTask =>
val result = testTask
println("Cleanup")
result
}
来源:https://stackoverflow.com/questions/19185144/test-cleanup-hook-not-executed-in-scala-play-application