2V0-72.22PSE · Question #19
Which statement about @TestPropertySource annotation is true? (Choose the best answer.)
The correct answer is D. Inlined properties defined in @TestPropertySource can be used to override properties defined. Option D is correct because @TestPropertySource is specifically designed to allow test-specific property overrides. Inlined properties (defined via the properties attribute, e.g., @TestPropertySource(properties = "foo=bar")) have the highest precedence among all property…
Question
Which statement about @TestPropertySource annotation is true? (Choose the best answer.)
Options
- AJava system properties have higher precedence than the properties loaded from
- BProperties defined @PropertySource are not loaded if @TestPropertySource is used.
- C@TestPropertySource annotation loads a properties file relative to the root of the project by
- DInlined properties defined in @TestPropertySource can be used to override properties defined
How the community answered
(48 responses)- A8% (4)
- B4% (2)
- C2% (1)
- D85% (41)
Explanation
Option D is correct because @TestPropertySource is specifically designed to allow test-specific property overrides. Inlined properties (defined via the properties attribute, e.g., @TestPropertySource(properties = "foo=bar")) have the highest precedence among all property sources in the test Environment, meaning they can override properties from files, @PropertySource, and even application configuration.
Why the distractors are wrong:
- A is incorrect -
@TestPropertySourceproperties have higher precedence than Java system properties, not lower. System properties sit below test property sources in the hierarchy. - B is incorrect -
@PropertySourcedefinitions are still loaded when@TestPropertySourceis used; they simply have lower precedence, not suppressed entirely. - C is incorrect -
@TestPropertySourceresolves property file locations relative to the classpath (defaulting to the package of the declaring test class), not the root of the project filesystem.
Memory tip: Think of @TestPropertySource inlined properties as the "last word" in your test environment - they sit at the top of the property source chain specifically so tests can reliably override any external configuration without fighting system-level settings.
Topics
Community Discussion
No community discussion yet for this question.