At first I had the following annotation above my test class:
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@AutoConfigureMockMvc
With that configuration it tries to connect to my database. I would like my test to run without any connection to a database, which is why I tried to change the annotations, so my test class now looks like this:
@RunWith(SpringRunner.class)
@DataJpaTest
@WebMvcTest(CitizenController.class)
@AutoConfigureMockMvc
public class CitizenControllerTest {
@Autowired
private MockMvc mockMvc;
@MockBean
private CitizenRepository citizenRepository;
@MockBean
private WeeklyCareRepository weeklyCareRepository;
@MockBean
private SubCategoryCareRepository subCategoryCareRepository;
@Autowired
private ObjectMapper objectMapper;
private static List<Citizen> mockCitizenList;
private String citizenJson;
However, I am now getting another error:
java.lang.IllegalStateException: Configuration error: found multiple declarations of @BootstrapWith for test class [controllers.CitizenControllerTest]: [@org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.context.SpringBootTestContextBootstrapper), @org.springframework.test.context.BootstrapWith(value=class org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTestContextBootstrapper)]
Is it possible to run my test without a database connection? If so, what am I doing wrong/missing?
Please login or Register to submit your answer