How to setup configuration files environments?

Hi all

I have the following environments:

  1. dev
  2. stage
  3. prod

Each environment will have different configuration and in akka documentation it says, that it is possible to include files.

Including files
Sometimes it can be useful to include another configuration file, for example if you have one application.conf with all environment independent settings and then override some settings for specific environments.

Specifying system property with -Dconfig.resource=/dev.conf will load the dev.conf file, which includes the application.conf

include "application"

akka { loglevel = “DEBUG” }

My project environment looks as the following:
enter image description here

When I do unit test, I would like to use dev.conf configuration file and I have to setup somehow, that it will take the dev.conf file.

As the doc says above:

Specifying system property with -Dconfig.resource=/dev.conf

It is not clear to me, how to do it. Where do I have to pass it?

The content of my dev.conf looks as the following:

include "application"

akka {loglevel = "DEBUG"}  

The question is, how to make sure, when the unit test is started, that the dev.conf file is going use?

Thanks

Since sbt by default will run the tests in the same JVM as itself, it is a bit tricky specifying system properties like that, it would require you to switch to forked tests, where a new JVM is started to run the tests.

Another, IMO easier, option is to explicitly select the dev.conf in your test cases, for example having a test base class that loads the config with ConfigFactory.load("dev.conf") and passes that to the testkit/ActorSystem the tests will use.

For the Akka typed testkit we have discussed always loading a specific application-test.conf but it has not been implemented yet. (Issue #25708)

1 Like