I have the following project structure for a Spring Boot App.
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.
-
Try reaming it to application-test. propertiesFrischling– Frischling2019年11月22日 04:20:22 +00:00Commented Nov 22, 2019 at 4:20
-
@Frischling, that didn't work. It throws an error 'Could not load Application Context'Kihats– Kihats2019年11月22日 04:27:27 +00:00Commented Nov 22, 2019 at 4:27
3 Answers 3
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
Comments
Create a application-test.properties under the src/main/resources with your test configuration.
than use like below on your test
@ActiveProfiles("test")
Comments
Try to do this, it can solve your problem forder mark
1 Comment
application.properties file in config folder