Search code examples
javaconfigurationakkatypesafetypesafe-stack

Typesafe Config: Load configuration from src/test/resources


This is a beginner question. So my app structure looks like

src/main/java/...
src/main/resources/application.conf

src/test/java/...
src/test/resources/module/test.module.conf

application.conf

location: mainLocation

test.module.conf

location: testLocation

In my test, I do

  @Test
  public void testLoadConfig() {
    final Config config = ConfigFactory.parseResources("test.module.conf");
    System.out.println(config);
  }

and what I see

Config(SimpleConfigObject({}))

Surely something is not right, but I can't spot it

UPDATE

When I do just

  @Test
  public void testActorForFailure() {
//    final Config config = ConfigFactory.load("test.module.conf");
    final Config config = ConfigFactory.load();
    System.out.println(config.getString("location"));

  }

I see

mainLocation

So overriding is not working, why?


Solution

  • If you want to load that test config file try this:

    ConfigFactory.load("modules/test.module")
    

    The base ConfigFactory.load() method looks to load 'application.conf'. If you want it to load a different file you need to tell it what that different file is.