简体   繁体   English

如何为sbt测试指定sbt 0.12.2的配置文件?

[英]How do I specify a config file with sbt 0.12.2 for sbt test?

I have a Play! 我有戏! project with unit tests and I am trying to run tests on my staging environment using sbt. 项目与单元测试,我试图使用sbt在我的登台环境中运行测试。 Before I upgraded to Play 2.1, when I was using Play 2.0.4 and sbt 0.11.3 I could do $ sbt -Dconfig.file=conf/staging.conf test . 在升级到Play 2.1之前,当我使用Play 2.0.4和sbt 0.11.3时,我可以进行$ sbt -Dconfig.file=conf/staging.conf test Now sbt test seems to use the default application.conf no matter what I specify for -Dconfig.file. 现在,无论我为-Dconfig.file指定什么, sbt test似乎都使用默认的application.conf。

sbt start -Dconfig.file=conf/staging.conf still works fine. sbt start -Dconfig.file=conf/staging.conf仍然可以正常工作。 Is this behavior a bug with sbt 0.12.2 or should I be specifying a config file for running tests in a different way? 这是sbt 0.12.2的错误,还是我应该指定一个配置文件以其他方式运行测试?

test is using forked jvm. 测试是使用分叉的jvm。 Use javaOptions sbt setting to pass jvm options to it eg 使用javaOptions sbt设置将jvm选项传递给它,例如

javaOptions ++= Seq("-Dconfig.file=conf/staging.conf")
or 要么

javaOptions ++= collection.JavaConversions.propertiesAsScalaMap(System.getProperties).map{ case (key,value) => "-D" + key + "=" +value }.toSeq

Similar approach is to just pass the config file to use, while triggering the sbt test 类似的方法是只通过配置文件即可使用,同时触发sbt测试

First, in the Build.scala file 首先,在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
)

Then, in the command line to run the test with integ.conf 然后,在命令行中使用integ.conf运行测试

sbt -Dtest.config=integ test

to use the default application.conf 使用默认的application.conf

sbt test 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM