Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. 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. Now sbt test seems to use the default application.conf no matter what I specify for -Dconfig.file.

sbt start -Dconfig.file=conf/staging.conf still works fine. 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?

like image 468
fpearsall Avatar asked Mar 14 '13 00:03

fpearsall


People also ask

How do I run a Scala test?

Run Scala tests with coverageOpen your project. Open the test in question in the editor. icon and select the Run 'name' with Coverage option.

How do I clear my sbt cache?

You can use Pretty Clean to clean the all of dev tools caches including SBT. PrettyClean also cleans the SBT project's target folder.


2 Answers

test is using forked jvm. Use javaOptions sbt setting to pass jvm options to it e.g.

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

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

like image 108
OlegYch Avatar answered Sep 24 '22 14:09

OlegYch


Similar approach is to just pass the config file to use, while triggering the sbt test

First, in the Build.scala file

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

sbt -Dtest.config=integ test

to use the default application.conf

sbt test 
like image 42
Karthik Chandraraj Avatar answered Sep 21 '22 14:09

Karthik Chandraraj