软件测试

spring Boot integration test wit

2017-08-30  本文已影响604人  张培_

情景描述

@RunWith(SpringRunner.class)
@WebMvcTest(TaskController.class)
public class DemoApplicationUnitTests {

    @Autowired
    private MockMvc mockMvc;

    @Test
    public void test_get_one_task_when_id_exist() throws Exception {
        Task task = new Task();
        task.setId(1);
        when(taskRepository.exists(1)).thenReturn(true);
        when(taskRepository.findOne(1)).thenReturn(task);

        mockMvc.perform(get("/tasks/1"))
                .andExpect(status().isOk())
                .andExpect(jsonPath("$.id",is(1)))
                .andExpect(jsonPath("$.text",is("zhangpei")))
                .andExpect(jsonPath("$.completed",is(0)));
    }
}

问题分析




反思

action

上一篇下一篇

猜你喜欢

热点阅读