I'm trying to test my REST Controller in my Spring Boot application. This is my test class
import com.binar.kelompok3.secondhand.repository.OffersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Test;
@WebMvcTest(HistoryController.class)
public class HistoryControllerTest {
@MockBean
private OffersRepository offersRepository;
@Autowired
private MockMvc mockMvc;
@Test
void signIn() throws Exception{
mockMvc.perform(get())
}
}
When I put @Autowired
on the MockMvc field Intellij gives me Could not autowire. No beans of 'MockMvc' type found
and the mockMvc.perform
method doesn't work.
I've tried changing @WebMvcTest
to
@SpringBootTest
@RunWith(SpringRunner.class)
@AutoConfigureMockMvc
But Intellij still gives me
Could not autowire. No beans of 'MockMvc' type found
when I hover my cursor on mockMvc
How can I autowired MockMvc? Thanks