2V0-72.22PSE · Question #24
Which two statements are true regarding Spring Boot Testing? (Choose two.)
The correct answer is C. @SpringBootTest is typically used for integration testing. D. Test methods annotated with @SpringBootTest will recreate the ApplicationContext. C is correct because @SpringBootTest loads the full Spring ApplicationContext, wiring together all layers (controllers, services, repositories), which is exactly what integration testing requires - verifying components work together end-to-end rather than in isolation. D is…
Question
Which two statements are true regarding Spring Boot Testing? (Choose two.)
Options
- A@TestApplicationContext is used to define additional beans or customizations for a test.
- BTest methods in a @SpringBootTest class are transactional by default.
- C@SpringBootTest is typically used for integration testing.
- DTest methods annotated with @SpringBootTest will recreate the ApplicationContext.
- E@SpringBootTest without any configuration classes expects there is only one class annotated
How the community answered
(44 responses)- A5% (2)
- B2% (1)
- C91% (40)
- E2% (1)
Explanation
C is correct because @SpringBootTest loads the full Spring ApplicationContext, wiring together all layers (controllers, services, repositories), which is exactly what integration testing requires - verifying components work together end-to-end rather than in isolation.
D is correct because @SpringBootTest triggers the creation of a real ApplicationContext for the test class. While Spring caches contexts between compatible test classes for performance, each distinct test configuration causes the context to be (re)created fresh.
Why the distractors are wrong:
- A is wrong - the correct annotation is
@TestConfiguration, not@TestApplicationContext(which doesn't exist in Spring). - B is wrong -
@SpringBootTesttests are not transactional by default; you must explicitly annotate with@Transactionalif you want rollback behavior. - E is wrong (though cut off) -
@SpringBootTestwithout explicit configuration searches up the package hierarchy for a@SpringBootApplication-annotated class; it does not require exactly one such class.
Memory tip: Think of @SpringBootTest as "boots up the whole app for testing" - it's heavy (full context = integration test) and it builds the context fresh when the configuration changes. When you see @Test + full context = @SpringBootTest; when you see lightweight/isolated = unit test with mocks.
Topics
Community Discussion
No community discussion yet for this question.