哪种类型的测试对Jenkins Continous Integration(Spring Boot App)有用

时间:2017-08-02 07:32:58

标签: java testing jenkins spring-boot

我的老板让我在Spring Boot应用程序上构建一些测试。

我问自己应该实施哪种类型的测试,考虑到目标是推动支持自动测试的Jenkins应用程序。

基于代码的测试

@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());

    }

完全模拟测试

@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();

    }

我在测试中非常新,我需要了解工作方法

0 个答案:

没有答案