Controller Mocking
Learn Controller Mocking (Spring MVC Testing, Spring MVC) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Fresher Notes Controller mocking means testing a controller in isolation by replacing its dependencies (services) with mocks, so only the web logic is verified. @MockBean puts a Mockito mock into the Spring context; when(...).thenReturn(...) defines its answers. verify checks that the controller called the service as expected, for example verify(service).save(any()) .