当前位置: 首页 > news >正文

网站开发工作如何南京疫情最新消息

网站开发工作如何,南京疫情最新消息,WordPress配置pdo,网站远程数据库一、测试需求描述 对服务后台一系列的http接口功能测试。 输入:根据接口描述构造不同的参数输入值(Json格式) 输出:字符串(传入的方式传入的字符串) http://localhost:8090/lctest/TestServer 二、程序设计…

一、测试需求描述

    对服务后台一系列的http接口功能测试。

    输入:根据接口描述构造不同的参数输入值(Json格式)

    输出:字符串(传入的方式+传入的字符串)

    http://localhost:8090/lctest/TestServer

二、程序设计

    1、Client程序设计

        读取Excel配置的测试用例数据

        发送参数Json格式给Server,接收Server的返回数据

        进行数据比对校验,返回测试结果,将数据插入到Excel中

    2、Server端程序设计

        接受Client的参数,进行解析

        发送返回数据给client

三、实现方法

    1、选用Java脚本来驱动测试

    2、采用Excel表格管理测试数据,包括用例的管理、测试数据录入、测试结果显示等等,这个需要封装一个Excel的类。

    3、调用http接口采用java自带的的API

    4、测试需要的将参数转化成字符串

    5、通过预期结果和实际结果的对比,将实际结果和对比结果写入Excel用例中,这里封装了一个类

    6、首次执行测试采用人工检查输出的是否正确,一旦正确写入Excel的期望结果中,如果发现错误手工修正为预期文件。

四、Excel表格设计

五、代码结构

六、实现代码

1、ExcelUtil.java

    

package client;import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.ArrayList;
import java.util.List;import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRichTextString;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;public class ExcelUtil {//读取Excel中数据public static List<Param> read() throws Exception{HSSFWorkbook wb = new HSSFWorkbook();HSSFSheet s = wb.createSheet();HSSFRow row = s.createRow(0);HSSFCell cell = row.createCell((int)0,0);//------------从xls读出数据wb = new HSSFWorkbook(new FileInputStream("D:\\learn\\test.xls"));s = wb.getSheetAt(0);//获得EXCEL行数int rowNums=s.getLastRowNum();//获得Excell列数//int columnNum=r.getPhysicalNumberOfCells();List<Param> params=new ArrayList<Param>();for(int i=1;i<=rowNums;i++){HSSFRow r = s.getRow(i);cell=r.getCell(0);Param param= new Param();param.setNo(r.getCell(0).getStringCellValue());param.setName(r.getCell(1).getStringCellValue());param.setAge(r.getCell(2).getStringCellValue());param.setSex(r.getCell(3).getStringCellValue());param.setExpResu(r.getCell(4).getStringCellValue());
//			 System.out.println(cell.getRichStringCellValue());params.add(param);}return params;}/*** 写入Excel,在任意坐标处写入数据。* String value:你要输入的内容* int x :行坐标,Excel从 0 算起* int y   :列坐标,Excel从 0 算起*/public static void writeCell(String filePath,int x,int y,String value) {try {// 创建Excel的工作书册 Workbook,对应到一个excel文档HSSFWorkbook wb = new HSSFWorkbook(new FileInputStream(filePath));HSSFSheet sheet=wb.getSheetAt(0);HSSFRow row=sheet.getRow(x);HSSFCell cell=row.getCell((short) y);cell.setCellValue(value);FileOutputStream os;os = new FileOutputStream(filePath);wb.write(os);os.close();} catch (Exception e) {e.printStackTrace();}}
}

2、JsonsUtil.java

    

package client;import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;/*** 使用json-lib构造和解析Json数据*/
public class JsonsUtil {/**将Bean转换成Map* 将Map转换Json数据*/public static String BuildJson(Param param) throws JSONException {Map<String, String> map1 = new HashMap<String, String>();map1.put("no", param.getNo());map1.put("name", param.getName());map1.put("age", param.getAge());map1.put("sex", param.getSex());
//         map1.put("expResu", param.getExpResu());// JSON格式数据解析对象JSONObject jo = new JSONObject();// 将Map转换为JSONArray数据JSONArray ja = new JSONArray();ja.put(map1);
//        System.out.println("JSONArray对象数据格式:"+ja.toString());jo.put("map", ja);
//        System.out.println("最终构造的JSON数据格式:"+jo.toString());return jo.toString();}/*** 解析Json数据**/public static JSONArray ParseJson(String jsonString) throws JSONException,ParseException {JSONObject jo = new JSONObject(jsonString);JSONArray ja = jo.getJSONArray("map");
//        System.out.println(ja.getJSONObject(0).getString("name"));return ja;}
}

3、Param.java

package client;public class Param {String no;//编号String name;//姓名String age;//年龄String sex;//性别String expResu;//期望结果String actResu;//实际结果String pass;//是否通过String desc;//描述public String getName() {return name;}public void setName(String name) {this.name = name;}public String getNo() {return no;}public void setNo(String no) {this.no = no;}public String getAge() {return age;}public void setAge(String age) {this.age = age;}public String getSex() {return sex;}public void setSex(String sex) {this.sex = sex;}public String getExpResu() {return expResu;}public void setExpResu(String expResu) {this.expResu = expResu;}public String getActResu() {return actResu;}public void setActResu(String actResu) {this.actResu = actResu;}public String getPass() {return pass;}public void setPass(String pass) {this.pass = pass;}public String getDesc() {return desc;}public void setDesc(String desc) {this.desc = desc;}
}

4、CompareRes.java

    

package client;public class CompareRes {int actResuNo=5;//测试结果在第五例int passNo=6;//对比结果在第六列public  void compare(String filePath,Param param,String actResu){ExcelUtil.writeCell(filePath,Integer.parseInt(param.getNo()),actResuNo,actResu);if(param.getExpResu().trim().equals(actResu)){ExcelUtil.writeCell(filePath,Integer.parseInt(param.getNo()),passNo,"Y");}else{ExcelUtil.writeCell(filePath,Integer.parseInt(param.getNo()),passNo,"N");}}
}

5、TestClient .java

package client;import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;public class TestClient {public static void main(String[]agrs){TestClient a=new TestClient();try {a.client();} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}public void client() throws Exception{List<Param> params = ExcelUtil.read();for(Param pa:params){try {// 接报文的地址String filePath="D:\\learn\\test.xls";String param= new JsonsUtil().BuildJson(pa);URL serverUrl= new URL("http://localhost:8090/lctest/TestServer");URLConnection uct= serverUrl.openConnection();HttpURLConnection hutc=(HttpURLConnection)uct;	// 设置报文参数hutc.setRequestMethod("POST");// 设置是否向httpUrlConnection输出,因为这个是post请求,参数要放在 http正文内,因此需要设为true, 默认情况下是false; hutc.setDoOutput(true);// 设置是否从httpUrlConnection读入,默认情况下是truehutc.setDoInput(true);	
//				hutc.setAllowUserInteraction(true);// 开启流,写入数据dataOutputStream out=hutc.getOutputStream();out.write(param.getBytes("UTF-8"));out.flush();out.close();// 获取返回的数据	StringBuffer buffer=new StringBuffer();BufferedReader reader = null;InputStream ins=hutc.getInputStream();reader = new BufferedReader(new InputStreamReader(ins,"UTF-8"));String sg=reader.readLine();if (sg!= null){buffer.append(sg);}System.out.println("接收返回值:" + buffer);new CompareRes().compare(filePath, pa, buffer.toString());} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}}
}

6、TestServer

public class TestServer extends HttpServlet {private static final long serialVersionUID = 1L;private static JSONArray ja;/*** @see HttpServlet#HttpServlet()*/public TestServer() {super();// TODO Auto-generated constructor stub}/*** @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)*/protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubtry {this.excute(request, response);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}/*** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)*/protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {// TODO Auto-generated method stubtry {this.excute(request, response);} catch (Exception e) {// TODO Auto-generated catch blocke.printStackTrace();}}public void excute(HttpServletRequest request,HttpServletResponse response) throws Exception{request.setCharacterEncoding("utf-8");response.setCharacterEncoding("UTF-8");response.setContentType("text/xml");String method=request.getMethod();String url=request.getRequestURI();String param;// 获取收到的报文BufferedReader reader = request.getReader();String line = "";line = reader.readLine();ja=new JsonsUtil().ParseJson(line);		StringBuffer resultBuffer=new StringBuffer();resultBuffer.append("访问方式"+method+"访问成功");resultBuffer.append("接收到的数据:"+line);PrintWriter out =response.getWriter();out.println(resultBuffer.toString());out.flush();out.close();}
}

7、web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"><servlet><servlet-name>TestServer</servlet-name><servlet-class>com.servlet.TestServer</servlet-class></servlet><servlet-mapping><servlet-name>TestServer</servlet-name><url-pattern>/lctest/TestServer</url-pattern></servlet-mapping>
</web-app>

Python接口自动化测试零基础入门到精通(2023最新版)

http://www.wangmingla.cn/news/33709.html

相关文章:

  • 做网站互联互通百度推广的步骤
  • wordpress 插件 弹窗深圳百度seo怎么做
  • 网页美工设计报价单seo营销外包
  • 什么网站可以做国外批发网湘潭网站设计外包公司
  • 网站优化网站建设公司seo关键词排名软件
  • 阿里巴巴官网网址是多少百度seo优化网站
  • 建设企业网站的申请互联广告精准营销
  • 如何阿里网站建设谷歌引擎搜索
  • 网站建设行业前景宁波免费seo排名优化
  • 沈阳网站wordpress官网入口
  • 做盗版网站会怎样页面seo是什么意思
  • 主机怎么做网站服务器排行榜软件
  • 自己做的网站根目录哪里找到十大接单推广平台
  • 江门网站推广技巧市场推广方案
  • 网站关键词排名如何做网站建设与优化
  • 购物网站html深圳网络推广外包公司
  • 个人网站建设目标百度平台营销宝典
  • 做跨境电商网站短视频营销成功的案例
  • 网站建设三要素seo博客写作
  • 河北专业网络营销收费公司360优化大师最新版下载
  • 手机挣钱最快的软件苏州seo关键词优化价格
  • 拟定建设方案物流网站百度信息流广告
  • 河北建设厅网站打不开是什么原因今日头条新闻最新消息
  • 深圳网站制作公司北京seo实战培训班
  • 嘉兴网站建设公司100个关键词
  • itc 做市场分析的网站企业宣传方式有哪些
  • 海南旅游网网页制作太原seo培训
  • 网站建设模块方案百度竞价客服电话
  • wordpress添加小工具栏seo手机端优化
  • 扬州做网站的公司哪个好全球网站流量排名查询