SBT不会调用Test.Setup上Play2项目(SBT doesn't call Tes

2019-10-18 02:51发布

这里是我的SBT编译:

  val main = play.Project(appName, appVersion, appDependencies).settings(defaultScalaSettings:_*)
    .settings(
    scalaVersion := "2.10.0",
    resolvers += .....
  )
    .configs(IntegrationTest)
    .settings( Defaults.itSettings : _*)
    .settings(
    testOptions in Test += Tests.Setup( () => println("Setup Test yoohooo") ),
    testOptions in Test += Tests.Cleanup( () => println("Cleanup Test yoohoo") ),
    scalaSource in Test <<= baseDirectory / "test/unit",
    parallelExecution in Test := true,

    testOptions in IntegrationTest += Tests.Setup( () => println("Setup Integration Test yoohoo") ),
    testOptions in IntegrationTest += Tests.Cleanup( () => println("Cleanup Integration Test yoohoo") ),
    scalaSource in IntegrationTest <<= baseDirectory / "test/integration",
    parallelExecution in IntegrationTest := false

  )

我可以启动两个任务testit:test ,但只打印文本的IntegrationTest,而不是常规的测试。

我看到Play2有相关的一些默认设置:

testOptions in Test += Tests.Setup { loader =>
  loader.loadClass("play.api.Logger").getMethod("init", classOf[java.io.File]).invoke(null, new java.io.File("."))
},

testOptions in Test += Tests.Cleanup { loader =>
  loader.loadClass("play.api.Logger").getMethod("shutdown").invoke(null)
},

是不是我的构建应该覆盖这些设置吗?

顺便说一句,我可以调用这个设置外部库或测试源类?

Answer 1:

也许这是SBT的约束。

SBT官方文件说

当一组分叉设置和清理行动,不支持。

https://github.com/sbt/sbt/blob/v0.12.2/src/sphinx/Detailed-Topics/Testing.rst#forking-tests

http://www.scala-sbt.org/0.12.2/docs/Detailed-Topics/Testing.html

fork in Test := true

从Play2.1.0默认

https://github.com/playframework/Play20/pull/654/files#L5L110



文章来源: SBT doesn't call Test.Setup on a Play2 project