Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify different application.conf for specs2 tests?

I have an IntelliJ IDEA project in Scala and started adding org.specs2 tests. I am having trouble finding out how to put in an application.conf file that will be used by the tests.

I have tried doing the following:

test
    resources
        application.conf 
    scala
        mypackage.myname
            MyTestSpec

then called

ConfigFactory.load()

in MyTestSpec. Nothing was loaded, though, neither the application.conf from my resources subfolder of the src folder, nor this one. My goal is to be able to write integration tests against some test environments (please let's not debate the validity of this goal...).

How to go about doing this or is there a better way of going about it? I started reading the specs2 documentation today and I am pretty new to Scala as well so I am just assuming here that this is how test configurations are supposed to work.

So far I have attempted to specify -Dconfig.file=my_test_conf_full path in the build configuration for the tests (from the Build/Configurations... menu in IntelliJ), however that did not make any difference.

Thank you.

like image 687
user2916547 Avatar asked Jun 05 '15 15:06

user2916547


People also ask

Where do I put application conf?

conf file that defines the defaults. you can add an application. conf file in the classpath (or an absolute path, or an URL). It only needs to contain the options that you override.

What is application conf?

application. conf is a file for application developers. A developer can set values for properties used by libraries in case they are not the same as defaults. Also he/she can declare his own properties and refer them from the code.


1 Answers

Using SBT

Place your custom configuration file at src/test/resources/application.test.conf.

Then, add this to your build.sbt:

// When running tests, we use this configuration
javaOptions in Test += s"-Dconfig.file=${sourceDirectory.value}/test/resources/application.test.conf",
// We need to fork a JVM process when testing so the Java options above are applied
fork in Test := true,
like image 65
Matthias Braun Avatar answered Sep 20 '22 19:09

Matthias Braun