[英]How do I specify a config file with sbt 0.12.2 for sbt test?
我有戏! 项目与单元测试,我试图使用sbt在我的登台环境中运行测试。 在升级到Play 2.1之前,当我使用Play 2.0.4和sbt 0.11.3时,我可以进行$ sbt -Dconfig.file=conf/staging.conf test
。 现在,无论我为-Dconfig.file指定什么, sbt test
似乎都使用默认的application.conf。
sbt start -Dconfig.file=conf/staging.conf
仍然可以正常工作。 这是sbt 0.12.2的错误,还是我应该指定一个配置文件以其他方式运行测试?
测试是使用分叉的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
类似的方法是只通过配置文件即可使用,同时触发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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.