标签:auth 测试 request ica value lib work autowire moc
package com.msun.drug.api.doctor;
import cn.hutool.core.date.DateTime;
import com.alibaba.fastjson.JSON;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
/**
* @description:
* @author: kevin
* @create: 2020-09-08 15:27
*/
@SpringBootTest
@RunWith(SpringRunner.class)
public class DoctorPatientApiTest {
@Autowired
private WebApplicationContext wac;
private MockMvc mockMvc;
// 在测试开始前初始化工作
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();
}
@Test
public void doctorRevokePatientDrugById() throws Exception {
String id = "";
mockMvc.perform(MockMvcRequestBuilders
.post("/doctorPatientApi/doctorRevokePatientDrugById")
.contentType(MediaType.APPLICATION_JSON)
.param("id",id))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(jsonPath("$.success").value(false))
.andDo(MockMvcResultHandlers.print());
// 存在请求结果
id = "1";
mockMvc.perform(MockMvcRequestBuilders
.post("/doctorPatientApi/doctorRevokePatientDrugById")
.contentType(MediaType.APPLICATION_JSON)
.param("id",id))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(jsonPath("$.success").value(false))
.andDo(MockMvcResultHandlers.print());
}
标签:auth 测试 request ica value lib work autowire moc
原文地址:https://www.cnblogs.com/zhenghengbin/p/13807213.html