2V0-72-22 practice question 12 of 15

Which statement about @TestPropertySource annotation is true? (Choose the best

Full set: 79 questions
Answer options
A:

A. Java system properties have higher precedence than the properties loaded from @TestPropertySource.

B:

B. Properties defined @PropertySource are not loaded if @TestPropertySource is used.

C:

C. @TestPropertySource annotation loads a properties file relative to the root of the project by default.

D:

D. Inlined properties defined in @TestPropertySource can be used to override properties defined in property files.

Correct answer
Correct Answer:
D. D. Inlined properties defined in @TestPropertySource can be used to override properties defined in property files.
Explanation

The @TestPropertySource annotation in Spring's testing framework provides a way to configure properties for integration tests. The properties attribute of this annotation allows for defining "inlined properties" as an array of strings. These inlined properties have a higher precedence than properties loaded from resource locations specified in the locations attribute of the same annotation. This feature is particularly useful for overriding specific properties for a single test case without needing to create a separate properties file.

Why Incorrect

A. Properties from @TestPropertySource have higher precedence than Java system properties, not the other way around.
B. Properties from @PropertySource are still loaded; @TestPropertySource simply has higher precedence and can override them.
C. By default, @TestPropertySource loads properties from the classpath, not relative to the project root.

References

1. Spring Framework Documentation, 6.1.x, "Testing - Context configuration with test property sources". Section 10.5.6. The documentation states, "Inlined properties have higher precedence than properties loaded from a resource location." It also details the full precedence order.

2. Spring Framework API Documentation for org.springframework.test.context.TestPropertySource. The Javadoc for the properties attribute explicitly mentions its higher precedence over properties loaded from locations.

Scroll to Top