Use @WebMvcTest to test REST APIs exposed through Controllers without the server part running. Only list Controllers that are being tested.
xxxxxxxxxx
@RunWith(SpringRunner.class)
@WebMvcTest(CarServiceController.class)
public class CarServiceControllerTests {
@Autowired
private MockMvc mvc;
@MockBean
private CarService carService;
@Test
public void getCarShouldReturnCarDetails() {
given(this.carService.schedulePickup(new Date(), new Route());)
.willReturn(new Date());
this.mvc.perform(get("/schedulePickup")
.accept(MediaType.JSON)
.andExpect(status().isOk());
}
}
https://tanzu.vmware.com/developer/guides/spring-boot-testing/