@SpringBootTest and context caching
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
explain the cost of full-context tests.
Planned topics
@SpringBootTeststarts the entire application context.- Spring caches contexts between tests with the same configuration; different configs mean a new context.
- Mock beans and different properties create new contexts, so use them sparingly.
- Use it for a few end-to-end checks; use slices for most.
Draft outline details
Demonstration
a timeline: first test starts the context (seconds); next tests with the same configuration reuse it; a test with a new mock bean starts another.
Check your understanding
Why can adding a @MockitoBean slow the suite?
Show answer
It changes the configuration, so Spring builds another context.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.