Spring-boot application-test.properties
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
In Spring Boot, application-test.properties is the conventional place to keep configuration that should apply only when the test profile is active. This is useful for swapping databases, changing logging levels, or disabling integrations during automated tests. The file itself does nothing until the profile is activated, so the important part is understanding how profile activation and property precedence work together.
Where the File Belongs
For test-specific configuration, the usual location is:
Keeping it under src/test/resources ensures the file is available during tests without becoming part of the normal production artifact in the same way as main application resources.
You can also use application-test.yml if the project prefers YAML. The profile name and loading behavior are the same.
Activate the test Profile
Spring Boot only loads application-test.properties when the test profile is active.
A common test setup is:
With @ActiveProfiles("test"), Spring Boot loads the standard configuration and then overlays the test profile properties on top of it.
Use It to Override the Main Configuration
Suppose the main application uses a real database:
A test profile can replace that with an in-memory database:
This is the most common reason to use the file: tests should not hit production-like infrastructure by accident.
Understand Property Precedence
Spring Boot combines properties from many sources. In simplified form, later and more specific sources override earlier ones.
For typical tests, that means:
- '
application.propertiesprovides defaults' - '
application-test.propertiesoverrides those defaults when thetestprofile is active' - annotations such as
@TestPropertySourceor inline test properties can override both
Example of an even more specific override:
That inline property beats whatever is defined in the profile file.
Use @TestPropertySource Only When Needed
If all tests should share the same profile configuration, application-test.properties plus @ActiveProfiles("test") is usually enough. @TestPropertySource is more useful when one test class needs a special override.
This keeps one-off differences local instead of turning application-test.properties into a patchwork of unrelated cases.
Keep Test Configuration Focused
A good test properties file usually contains only things that genuinely differ from normal runtime configuration, such as:
- in-memory database settings
- test log levels
- disabled schedulers or integrations
- shorter timeouts
It should not become a second full production-style configuration file unless there is a real reason. The smaller it is, the easier it is to understand what the tests are intentionally changing.
Common Pitfalls
- Creating
application-test.propertiesbut never activating thetestprofile. - Putting the file in the wrong resources directory so tests do not see it.
- Duplicating the entire main configuration instead of overriding only what tests need.
- Forgetting that inline test properties or
@TestPropertySourcecan override profile values. - Letting tests hit real external services because the test profile was incomplete.
Summary
- '
application-test.propertiesis the conventional Spring Boot configuration file for thetestprofile.' - It is typically stored in
src/test/resources. - The file is only applied when the
testprofile is active, often through@ActiveProfiles("test"). - Use it to override main configuration for safe, isolated test behavior.
- Keep it focused and remember that more specific test property sources can still override it.
Related reading
- spring-boot application without a datasource
- Spring-boot automatically import applicationContext.xml?
- spring-boot default log location
- Spring-boot default profile for integration tests
- Spring-boot default profile for integration tests
- Spring Async - no data found in integration test
- Spring-Boot execute data.sql in one profile only
- spring-boot Fatal error compiling invalid target release 17

OOD Fundamentals
Master object-oriented design from first principles, SOLID, design patterns, and classic interview problems with hands-on coding.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.