【问题标题】:Set javaOptions in Test for Play/SBT在 Test for Play/SBT 中设置 javaOptions
【发布时间】:2016-01-28 03:27:28
【问题描述】:

我为单元测试配置了 build.sbt 以使用不同的 Play(Scala 为 2.3.9 和 SBT 0.13.5)配置,

javaOptions in Test ++= Seq("-Dconfig.file=/home/kitty/acme/test/resources/test-application.conf")

Play 没有选择test-application.conf,而是在conf 中使用了application.conf。 AFAIK,在这种情况下没有scalaOption。但是,如果我在命令行中包含-Dconfig.file,它就可以正常工作,

sbt test -Dconfig.file=/home/kitty/acme/test/resources/test-application.conf

我该如何解决这个问题?谢谢。

【问题讨论】:

    标签: scala unit-testing playframework


    【解决方案1】:

    javaOptions in Test ++= Seq("-Dconfig.file=/home/kitty/acme/test/resources/test-application.conf") 不起作用,因为我的 fork in Testfalse。因此,将fork 设置为true 即可。 -Dconfig.resource-Dconfig.file 一样,也是一样的。如果没有分叉,SBT 将不会捡起它。严格来说,javaOptions 仅适用于 forktrue 如提到的 here

    【讨论】:

      【解决方案2】:

      你快到了,你可以像这样强制 JVM 选项

      javaOptions in Test ++= Seq("-Dconfig.file=/home/kitty/acme/test/resources/test-application.conf")

      config.file 也采用相对路径,例如 conf/test-application.conf

      【讨论】:

      • 没有。这是行不通的。在 SBT reload 期间,它会导致“Seq[String] 无法附加到 Seq[sbt.TestOption]”错误。然后我尝试testOptions in Test ++= Seq(Tests.Argument("-Dconfig.file=/home/kitty/test/resources/test-application.conf")),SBT 继续,但test-application.conf 未被读取。
      • 我的错,答案中的错字。是javaOptions,我来修改
      • 不是我说的在我的问题中不起作用吗?
      • 我刚刚重读了一遍,对不起,你是对的。这在 2.3.x 和 2.4.x 上对我有用,但是我使用的是来自 conf/ 目录的相对路径,你能试试吗?
      • 还是不行。和fork in Test := falseparallelExecution in Test := false有关系吗?
      猜你喜欢
      • 1970-01-01
      • 2019-06-27
      • 2013-11-09
      • 2013-07-31
      • 2017-01-16
      • 2015-10-30
      • 1970-01-01
      • 1970-01-01
      • 2013-08-19
      相关资源
      最近更新 更多