接口测试中三种传参请求(Map、request、Integer)解析
注册企业接口传入的是一个request,查询企业接口传入的是一个integer;根据名称和国家名称模糊匹配接口传入的是一个Map;
针对三种不同的传参我怎么作接口测试呢?
1 package com.web.crm.services; 2 3 import java.util.ArrayList; 4 import java.util.HashMap; 5 import java.util.List; 6 import java.util.Map; 7 import org.apache.commons.lang.StringUtils; 8 import org.springframework.beans.factory.annotation.Autowired; 9 import org.springframework.stereotype.Service; 10 11 12 @Service 13 public class test { 14 @Autowired 15 private ICustomerInterface CustomerInterface; 16 @Autowired 17 private IShippingPortcodeInterface ShippingPortcodeInterface; 18 19 //test 20 @SuppressWarnings({ "rawtypes" }) 21 public List<TestResult> test(){ 22 //返回结果 23 List<TestResult> result = new ArrayList<TestResult>(); 24 /** 25 * 功能描述:注册企业 26 * CustomerResponse registerCustomer(CustomerRequest<?> request) 27 * 接口请求带request 案例 28 */ 29 //实例化一个请求 30 CustomerRequest request = new CustomerRequest(); 31 //实例化一个参数 32 CusCustomerEntity customerEntity = new CusCustomerEntity(); 33 customerEntity.setCusName("微软"); 34 //将参数写人请求 35 request.setEntity(customerEntity); 36 //实例化一个参数 37 CusEmployeeEntity CusEmployeeEntity = new CusEmployeeEntity(); 38 CusEmployeeEntity.setEmpTypeId(123); 39 CusEmployeeEntity.setCompanyEmail("yiy11@12.com"); 40 CusEmployeeEntity.setMobilePhone("13400065433"); 41 //将参数写人请求 42 request.setEmployeeEntity(CusEmployeeEntity); 43 //实例化一个响应 44 CustomerResponse response = new CustomerResponse(); 45 //将请求传入被测接口方法 46 response=CustomerInterface.registerCustomer(request); 47 //逻辑判断getResultCode是否10000 48 if (StringUtils.equals(response.getResultCode(), ReturnResult.SUCCESS.getResultCode())) { 49 result.add(new TestResult(AlertMessageLevel.SUCCESS, "注册企业", response.getResultCode(), response 50 .getResultMessage())); 51 } else { 52 result.add(new TestResult(AlertMessageLevel.ERROR, "注册企业", response.getResultCode(), response 53 .getResultMessage())); 54 } 55 56 /** 57 * 功能描述:查询企业 58 * CustomerResponse getCustomerById(Integer id) 59 * 接口请求可以直接入参 案例 60 */ 61 //定义入参类型并赋值 62 Integer id=1; 63 //实例化一个响应 64 CustomerResponse response1 = new CustomerResponse(); 65 //将定义参数传入被测接口方法 66 response1=CustomerInterface.getCustomerById(id); 67 //逻辑判断getResultCode是否10000 68 if (StringUtils.equals(response1.getResultCode(), ReturnResult.SUCCESS.getResultCode())) { 69 result.add(new TestResult(AlertMessageLevel.SUCCESS, "查询企业", response1.getResultCode(), response1 70 .getResultMessage())); 71 } else { 72 result.add(new TestResult(AlertMessageLevel.ERROR, "查询企业", response1.getResultCode(), response1 73 .getResultMessage())); 74 } 75 76 /** 77 * 功能描述:根据名称和国家名称模糊匹配 78 * ShippingPortcodeResponse queryAllPortcodeCountry(java.util.Map<java.lang.String,java.lang.Object> paramMap) 79 * 接口请求带Map 案例 80 */ 81 Map<java.lang.String,java.lang.Object> wy = new HashMap<java.lang.String,java.lang.Object>(); 82 wy.put("1", 1); 83 ShippingPortcodeResponse response2 = new ShippingPortcodeResponse(); 84 response2 = ShippingPortcodeInterface.queryAllPortcodeCountry(wy); 85 if (StringUtils.equals(response2.getResultCode(), ReturnResult.SUCCESS.getResultCode())) { 86 result.add(new TestResult(AlertMessageLevel.SUCCESS, "根据名称和国家名称模糊匹配", response2.getResultCode(), response2 87 .getResultMessage())); 88 } else { 89 result.add(new TestResult(AlertMessageLevel.ERROR, "根据名称和国家名称模糊匹配", response2.getResultCode(), response2 90 .getResultMessage())); 91 } 92 93 94 return result; 95 }}
技术微信群:
加微信:wonter 发送:技术Q
医疗微信群:
加微信:wonter 发送:医疗Q
更多文章关注公众号:
加微信:wonter 发送:技术Q
医疗微信群:
加微信:wonter 发送:医疗Q
更多文章关注公众号: