0

I want to have two application.properties files:
1. src/main/resources/application.properties
2. src/test/resources/application.properties
but I want that during test run it will use both files.
for instance:
In src/main/resources/application.properties:

a=b
c=d

In src/test/resources/application.properties:

e=f

and during test run I will be able use all the properties I listed from both files.

@Value("${a}")
private String a;
@Value("${c}")
private String c;
@Value("${e}")
private String e;

Is it possible?
If not - what is the best practice to do what I want? Thanks.

3
  • Why do you need an additional variable "e" for tests? Ideally you should be using same set of variables in application and its tests. Commented Dec 9, 2018 at 13:42
  • A Spring boot app will look first in the application-xxx.properties associated to its current configuration (eg application-dev.properties for development), then default to the application.properties file if the property it's looking for isn't found. How about a application.properties which contains a=b, c=d, then in your application-test.properties set e=f ? Commented Dec 9, 2018 at 13:45
  • In my case its relevant because I want to set the pact broker details in application-test.properties (because tht's relevant only for pact tests). I need the other configurations which set in application.properties as well. Otherwise, it's not getting compiled. Commented Dec 9, 2018 at 19:23

1 Answer 1

0

SOLVED:

I had to use src/test/resources/application-test.properties (and not src/test/resources/application.properties) and add the following annotation:

@TestPropertySource("classpath:application-test.properties")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.