My boss asked me to build some test on our Spring Boot application.
I'm asking myself which type of test should I implement, considering that the goal is to push the app on Jenkins that supports auto Testing.
Code based Test
@RunWith(SpringRunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class ConfigTagControllerTestReal {
@Autowired
MockMvc mockMvc;
@Test
public void shouldReturnTheTagName() throws Exception{
this.mockMvc.perform(get("/configtag/librerie"))
.andDo(print())
.andExpect(status().isOk());
}
Completely Mock Test
@RunWith(SpringRunner.class)
@WebMvcTest(value = ConfigTagController.class , secure = false)
public class ConfigTagControllerTestMocked {
@Autowired
private MockMvc mockMvc;
@MockBean
private ConfigTagService service;
@Test
public void shouldFindTheTagName() throws Exception{
Collection<String> mockPaths= new ArrayList<>();
ConfigTagEntity mockTag = new ConfigTagEntity("culo",mockPaths);
Mockito.when(service.getByName(Mockito.anyString())).thenReturn(mockTag);
RequestBuilder requestBuilder = MockMvcRequestBuilders.get("/configtag/culo")
.accept(MediaType.APPLICATION_JSON);
MvcResult result = mockMvc.perform(requestBuilder).andReturn();
}
I'm very new in testing and i need to understand the working method
Aucun commentaire:
Enregistrer un commentaire