2V0-72-22 practice question 6 of 15

Which statement is true? (Choose the best

Full set: 79 questions
Answer options
A:

A. @ActiveProfiles is a class-level annotation that is used to instruct the Spring TestContext Framework to record all application events that are published in the ApplicationContext during the execution of a single test.

B:

B. @ActiveProfiles is a class-level annotation that you can use to configure how the Spring TestContext Framework is bootstrapped.

C:

C. @ActiveProfiles is a class-level annotation that you can use to configure the locations of properties files and inlined properties to be added to the set of PropertySources in the Environment for an ApplicationContext loaded for an integration test.

D:

D. @ActiveProfiles is a class-level annotation that is used to declare which bean definition profiles should be active when loaded an ApplicationContext for an integration test.

Correct answer
Correct Answer:
D. D. @ActiveProfiles is a class-level annotation that is used to declare which bean definition profiles should be active when loaded an ApplicationContext for an integration test.
Explanation

The @ActiveProfiles annotation is a core feature of the Spring TestContext Framework used in integration testing. It is a class-level annotation that lets you specify which bean definition profiles should be active when the ApplicationContext is loaded for the test. This allows developers to selectively register different bean configurations for testing environments, such as using an in-memory database for tests instead of a production database, without changing application code.

Why Incorrect

A: This describes the @RecordApplicationEvents annotation, which is used for testing application event listeners. B: This describes the @BootstrapWith annotation, which is used for customizing the test context bootstrapping strategy. C: This describes the @TestPropertySource annotation, which is used for adding test-specific properties to the environment.

References

1. Spring Framework Documentation, v6.0.11, "Part II. Testing", Section 13. "Testing", Subsection 13.3. "Spring TestContext Framework", Sub-subsection 13.3.4. "Context Management". The documentation states: "@ActiveProfiles is a class-level annotation that is used to declare which bean definition profiles should be active when loading an ApplicationContext for an integration test."

2. Spring Framework Documentation, v5.3.29, "Testing", Section 6.3.4. "Context Management and Caching", paragraph on "Activating bean definition profiles with @ActiveProfiles". This section provides the same definition and examples of its usage in test classes.

Scroll to Top