关于接口测试的一些资料总结

百度文档-关于api的一些内容




https://wenku.baidu.com/view/c1db6b1166ec102de2bd960590c69ec3d5bbdbfa.html?rec_flag=default&mark_pay_doc=2&mark_rec_page=1&mark_rec_position=3&mark_rec=view_r_1&clear_uda_param=1


https://wenku.baidu.com/view/5ce24fe1988fcc22bcd126fff705cc1755275f9a.html


自动化项目的创建
https://wenku.baidu.com/view/a75832ccb9f67c1cfad6195f312b3169a451ea86.html?rec_flag=default&mark_pay_doc=2&mark_rec_page=1&mark_rec_position=4&mark_rec=view_r_1&clear_uda_param=1


阿里的部分
https://ask.seowhy.com/article/20600


Jenkins实现CI功能
http://ju.outofmemory.cn/entry/331845


纯粹的接口测试用例
https://blog.csdn.net/Jane_Liee/article/details/78527859


按照
https://www.cnblogs.com/findyou/p/5388853.html






package findyou.Interface;
import org.codehaus.jettison.json.JSONException;//jason解析的方法
import org.codehaus.jettison.json.JSONObject;//jason解析的方法
public class Common {
    /**
     * 解析Json内容
     * 
     * @author Findyou
     * @version 1.0 2015/3/23
     * @return JsonValue 返回JsonString中JsonId对应的Value
     **/
    public static String getJsonValue(String JsonString, String JsonId) {
        String JsonValue = "";
        if (JsonString == null || JsonString.trim().length() < 1) {//所有起始和结尾的空格都被删除了
            return null;
        }
        try {
            JSONObject obj1 = new JSONObject(JsonString);
            JsonValue = (String) obj1.getString(JsonId);//  以 Java 编程语言中 String 的形式获取此 ResultSet 对象的当前行中指定列的值
        } catch (JSONException e) {
            e.printStackTrace();////在命令行打印异常信息在程序中出错的位置及原因。
        }
        return JsonValue;
    }
}




getCityWeathe.java源码 


package findyou.Interface;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
public class getCityWeather {
    private String url="";
    
    public String geturl() {
        return url;
    }


    public String getHttpRespone(String cityCode) throws IOException {
        String line = "";
        String httpResults = "";
        url=("http://www.weather.com.cn/data/cityinfo/"
                + cityCode + ".html");
        try {
            HttpURLConnection connection = URLConnection.getConnection(url);//获取此 URL 连接的内容。
            DataOutputStream out = null;//许应用程序以与机器无关方式将Java基本数据类型写到底层输出流
            connection.connect();// 使用 connect 方法建立到远程对象的实际连接。
            out = new DataOutputStream(connection.getOutputStream());//getOutputStream用于返回Servlet引擎创建的字节输出流对象,Servlet程序可以按字节形式输出响应正文。
            out.flush();//清空此数据输出流。
            out.close();//关闭此数据输出流
            BufferedReader reader = new BufferedReader(new InputStreamReader(//包装字符流,将字符流放入缓存里,先把字符读到缓存里,到缓存满了或者你flush的时候,再读入内存,就是为了提供读的效率而设计的
                    connection.getInputStream()));
            while ((line = reader.readLine()) != null) {//每读一行进行一次写入动作 
                httpResults = httpResults + line.toString();//ToString方法会返回一个“以文本方式表示”此对象的字符串
            }
            reader.close();
            // 断开连接
            connection.disconnect();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return httpResults;
    }
}




4.URLConnection.java源码 
复制代码
package findyou.Interface;
import java.net.HttpURLConnection;
import java.net.URL;
public class URLConnection {    
    public static HttpURLConnection getConnection(String url){
        HttpURLConnection connection = null;
        try {
            // 打开和URL之间的连接
            URL postUrl = new URL(url);
            connection = (HttpURLConnection) postUrl.openConnection();
             // 设置通用的请求属性
            connection.setDoOutput(true);//设置是否向httpUrlConnection输出
            connection.setDoInput(true);//设置是否从httpUrlConnection读入,默认情况下是true
            connection.setRequestMethod("GET");//设定请求的方法为"get"
            connection.setUseCaches(false);//是否可以使用缓存,Post 请求不能使用缓存
            connection.setInstanceFollowRedirects(true);//是否使用重定向
            connection.setRequestProperty("Content-Type", "application/json");//是否使用重定向
            connection.setRequestProperty("Charset", "utf-8");//(如果不设此项,在传送序列化对象时,当WEB服务默认的不是这种类型时可能抛java.io.EOFException) 
            connection.setRequestProperty("Accept-Charset", "utf-8");//
        } catch (Exception e) {
            e.printStackTrace();
        } 
        return connection;
    }
}

猜你喜欢

转载自blog.csdn.net/liangdeniu/article/details/80194287