Yuchen
Yuchen

Reputation: 33036

Load different config file in unit test with ConfigFactory

I have different configuration files in the main application:

In the main app, I can load different configurations with the following, where "integration.conf" is defined as an environment variable:

ConfigFactory.load("integration.conf")

However, the same function doesn't seem to work in unit test. Nothing is loaded with the above code. I tried the following, with no parameter, then it loads the default applicaton.conf with no problem:

ConfigFactory.load()

How do we load a specific config file in the unit test?


I've also tried using a relative path:

ConfigFactory.load("../main/resources/integration.conf")

and even absolute path:

ConfigFactory.load("/Users/.../src/main/resources/integration.conf")

But neither of them work.


Edit:

I realize that staging.conf and production.conf are loaded properly after @pedromss's comment. And the only problematic one is integration.conf. It is probably because integration.conf only has one line:

integration.conf:

include file("application.conf")

It seems that the issue is that include file("application.conf") doesn't work? My other configurations for staging and production actually override the default values in application.conf:

staging.conf:

include file("application.conf")
foo {
    bucket="bucket-staging"
}

It looks like the issue is include file("xxx") should be include "xxx". Surprised that only the later works in Unit tests.

Upvotes: 0

Views: 3121

Answers (1)

pedromss
pedromss

Reputation: 2453

From the documentation:

include "application.conf" - Then you may override configurations.

include file("application.conf") doesn't work and I don't see it in the documentation.

Upvotes: 1

Related Questions