【问题标题】:How do I specify a config file with sbt 0.12.2 for sbt test?如何为 sbt 测试指定 sbt 0.12.2 的配置文件?
【发布时间】:2013-03-02 04:55:29
【问题描述】:
我有戏!带有单元测试的项目,我正在尝试使用 sbt 在我的登台环境上运行测试。在升级到 Play 2.1 之前,当我使用 Play 2.0.4 和 sbt 0.11.3 时,我可以使用 $ sbt -Dconfig.file=conf/staging.conf test。现在sbt test 似乎使用默认的application.conf,无论我为-Dconfig.file 指定什么。
sbt start -Dconfig.file=conf/staging.conf 仍然可以正常工作。这种行为是 sbt 0.12.2 的错误还是我应该指定一个配置文件来以不同的方式运行测试?
【问题讨论】:
-
如果您只想将 java 选项添加到 sbt test 而不是其他配置,那么您可以执行 javaOptions in Test += "-Dconfig.file=conf/test.conf" link
标签:
playframework
playframework-2.0
sbt
playframework-2.1
【解决方案1】:
测试正在使用分叉的 jvm。
使用 javaOptions sbt 设置将 jvm 选项传递给它,例如
javaOptions ++= Seq("-Dconfig.file=conf/staging.conf")
或
javaOptions ++= collection.JavaConversions.propertiesAsScalaMap(System.getProperties).map{ case (key,value) => "-D" + key + "=" +value }.toSeq
【解决方案2】:
类似的方法是只传递配置文件来使用,同时触发 sbt 测试
首先,在 Build.scala 文件中
val testOptions = "-Dconfig.file=conf/" + Option(System.getProperty("test.config")).getOrElse("application") + ".conf"
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
javaOptions in Test += testOptions
)
然后,在命令行中用 integ.conf
运行测试
sbt -Dtest.config=integ test
使用默认的application.conf
sbt test