Controller and Service

@Service  
class MyService {  
    fun getMessage(): String {  
        return "hello!"  
    }  
}

Calling the service from a controller,

@RestController  
class MyController(private val myService: MyService) {  
    @GetMapping("/")  
    fun sayHello(): String {  
        return myService.getMessage()  
    }  
}

Testing with @WebMvcTest

@WebMvcTest(MyController::class, MyService::class)
class IntegrationTest(@Autowired val mockMvc: MockMvc) {
    @Test
    fun shouldReturnHello() {
        this.mockMvc.perform(MockMvcRequestBuilders.get("/"))
            .andDo(print())
            .andExpect(status().isOk)
            .andExpect(content().string("hello!"))
    }
}

Testing with @SpringBootTest

@SpringBootTest  
@AutoConfigureMockMvc  
class IntegrationTest(@Autowired val mockMvc: MockMvc) {    
    @Test  
    fun shouldReturnHello() {  
        this.mockMvc.perform(MockMvcRequestBuilders.get("/"))  
            .andDo(print())  
            .andExpect(status().isOk)  
            .andExpect(content().string("hello!"))  
    }  
}