MockMvc vs real HTTP
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
choose the right kind of API test.
Planned topics
- MockMvc (
@WebMvcTest) tests the web layer without a real server: fast, services mocked. - Real HTTP tests (
@SpringBootTestwith a random port) test the whole stack, including security, serialization, and the database. - Use MockMvc for controller rules (validation, status codes, mapping); use real HTTP for journeys.
- Mix both; most endpoint rules in MockMvc, a few journeys in full tests.
- Both can use Testcontainers if the database is involved.
Draft outline details
Demonstration
a table: speed, what is real, what is mocked, best for.
Check your understanding
Which is faster, MockMvc or a full HTTP test?
Show answer
MockMvc.
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.