Test cleanup hook not executed in scala play application

旧时模样 提交于 2019-12-24 14:43:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!