3

I have the following project structure for a Spring Boot App.

enter image description here

The issue is, whenever I run tests, the Spring Boot App uses the application.properties in the config folder in the root of the project instead of the application.properties in src > test > resources folder.

So as a hack when running tests, I scramble the name of the application.properties in the config folder.

How do I tell Spring Boot to use the application.properties in the test location when running tests without touching config > application.properties?

I don't want to keep renaming the file depending on whether I am running the application or running tests.

asked Nov 22, 2019 at 4:17
2
  • Try reaming it to application-test. properties Commented Nov 22, 2019 at 4:20
  • @Frischling, that didn't work. It throws an error 'Could not load Application Context' Commented Nov 22, 2019 at 4:27

3 Answers 3

5

You can create a configuration file (application-test.properties) under your src/main/resources folder and then use @TestPropertySource(locations = "classpath:application-test.properties") on your test

answered Nov 22, 2019 at 5:28
Sign up to request clarification or add additional context in comments.

Comments

2

Create a application-test.properties under the src/main/resources with your test configuration.

than use like below on your test

@ActiveProfiles("test")
answered Nov 22, 2019 at 4:33

Comments

1

Try to do this, it can solve your problem forder mark

answered Nov 22, 2019 at 4:25

1 Comment

still hasn't worked. It's using the application.properties file in config folder

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.