lesnar
lesnar

Reputation: 2480

Spring boot Testing - Mock configurations

I want to write test for one of my Spring Service and one of the method in service is like this:

private void loadConfig() throws JsonParseException, JsonMappingException, IOException {
     // it loads config.json file and sets it in global variable
}

It loads the config.json file from classpath.

Now my question is: Is it possible to somehow define that for Tests

it should look for config-test.json instead of config.json ? Assume i have config-test.json on my classpath.

May be some annotation on method, I did not find much help from official doc.

Any hint would be highly appreciated.

Upvotes: 2

Views: 487

Answers (1)

Eugene Ustimenko
Eugene Ustimenko

Reputation: 322

You should use filename as method parameter, or try to use @PropertySource and Spring Environment for each ApplicationContext production as well as test.

Upvotes: 2

Related Questions