import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Matchers;
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.http.MediaType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.ResultActions;
import java.util.ArrayList;
import java.util.List;
import static org.mockito.BDDMockito.given;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
/**
* Created by ji_pengyun on 17-7-11.
*/
@RunWith(SpringJUnit4ClassRunner.class)
@WebMvcTest(MaintCompletionEvaluationController.class)
//新创建一个启动类。去掉mybatis的mapperScan注解。
@ContextConfiguration(classes = {com.chinamobile.cmss.test_support.ConfigurationForTest.class})
public class MaintCompleteEvaluationControllerTest {
@MockBean
private MaintCompletionEvaluationService maintCompleteEvaluationService;
@MockBean
private MaintPointResponseService maintPointResponseService;
@MockBean
private TaskService taskService;
@MockBean
private SubTaskService subTaskService;
@MockBean
private MaintCompleteService maintCompleteService;
@MockBean
private BusinessDataCompleteService businessDataCompleteService;
@Autowired
private MockMvc mvc;
//get 请求
@Test
public void testGetMaintCompletionEvaluationSum()
controller单元测试代码
最新推荐文章于 2024-08-15 17:08:02 发布
该博客展示了如何使用Spring Boot的MockMvc进行Controller单元测试,包括GET和POST请求的测试。通过创建MockBean模拟Service层操作,并设置预期响应,确保Controller的正确行为。测试覆盖了不同的请求参数组合。
摘要由CSDN通过智能技术生成