在Scala Play应用程序中未执行测试清理挂钩 [英] Test cleanup hook not executed in scala play application
本文介绍了在Scala Play应用程序中未执行测试清理挂钩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的Build.scala文件
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")
)
)
}
推荐答案
testOptions in Test += Tests.Cleanup
不适用于另一个Stackoverflow答案.
但是有解决方法:
将fork设置为false
这很简单,但可能会降低测试速度,因为它们不会并行执行.
This is simple but may slow down your tests because they won't be executed in parallel.
sbt.Keys.fork in Test := false
使用测试框架
例如 http://doc.scalatest.org /1.9.2/index.html#org.scalatest.BeforeAndAfterAll 和受保护的方法afterAll()
For example http://doc.scalatest.org/1.9.2/index.html#org.scalatest.BeforeAndAfterAll with the protected method afterAll()
覆盖测试任务
我的最爱.
test in Test ~= { testTask =>
val result = testTask
println("Cleanup")
result
}
这篇关于在Scala Play应用程序中未执行测试清理挂钩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文