nerdexam
Broadcom-VMware

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…

Testing

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)
  • A
    8% (4)
  • B
    4% (2)
  • C
    2% (1)
  • D
    85% (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 - @TestPropertySource properties have higher precedence than Java system properties, not lower. System properties sit below test property sources in the hierarchy.
  • B is incorrect - @PropertySource definitions are still loaded when @TestPropertySource is used; they simply have lower precedence, not suppressed entirely.
  • C is incorrect - @TestPropertySource resolves 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

#@TestPropertySource#Test Configuration#Property Precedence#Spring Testing

Community Discussion

No community discussion yet for this question.

Full 2V0-72.22PSE Practice