zoukankan      html  css  js  c++  java
  • 十三、postman导出java代码

    • 导出成java的OkHttp代码
    • 使用Junit进行接口自动化测试
    • 使用fastJSON解析json字符串

    创建个实体类

    package com.netease.AcFunTest;
    
    public class V2exNode {
        private int id;
        private String name;
        private String url;
        private String title;
        private String title_alternative;
        private int topics;
        private int stars;
        private String headers;
        private String footer;
        private long created;
        private String avatar_mini;
        private String avatar_large;
    
        public int getId() {
            return id;
        }
    
        public void setId(int id) {
            this.id = id;
        }
    
        public String getName() {
            return name;
        }
    
        public void setName(String name) {
            this.name = name;
        }
    
        public String getUrl() {
            return url;
        }
    
        public void setUrl(String url) {
            this.url = url;
        }
    
        public String getTitle() {
            return title;
        }
    
        public void setTitle(String title) {
            this.title = title;
        }
    
        public String getTitle_alternative() {
            return title_alternative;
        }
    
        public void setTitle_alternative(String title_alternative) {
            this.title_alternative = title_alternative;
        }
    
        public int getTopics() {
            return topics;
        }
    
        public void setTopics(int topics) {
            this.topics = topics;
        }
    
        public int getStars() {
            return stars;
        }
    
        public void setStars(int stars) {
            this.stars = stars;
        }
    
        public String getHeaders() {
            return headers;
        }
    
        public void setHeaders(String headers) {
            this.headers = headers;
        }
    
        public String getFooter() {
            return footer;
        }
    
        public void setFooter(String footer) {
            this.footer = footer;
        }
    
        public long getCreated() {
            return created;
        }
    
        public void setCreated(long created) {
            this.created = created;
        }
    
        public String getAvatar_mini() {
            return avatar_mini;
        }
    
        public void setAvatar_mini(String avatar_mini) {
            this.avatar_mini = avatar_mini;
        }
    
        public String getAvatar_large() {
            return avatar_large;
        }
    
        public void setAvatar_large(String avatar_large) {
            this.avatar_large = avatar_large;
        }
    }

    引入3个jar包

        <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>4.12</version>
                <scope>test</scope>
            </dependency>
            <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>fastjson</artifactId>
                <version>1.2.13</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/com.squareup.okhttp/okhttp -->
            <dependency>
                <groupId>com.squareup.okhttp</groupId>
                <artifactId>okhttp</artifactId>
                <version>2.7.5</version>
            </dependency>

    执行测试类

    package com.netease.AcFunTest;
    
    import com.alibaba.fastjson.JSON;
    import com.squareup.okhttp.OkHttpClient;
    import com.squareup.okhttp.Request;
    import com.squareup.okhttp.Response;
    
    import java.io.IOException;
    import org.junit.*;
    import org.junit.jupiter.api.Test;
    
    public class V2exAPITest {
        @Test
        private void nodeApi() throws IOException{
            OkHttpClient client = new OkHttpClient();
            for (String nodeName : new String[]{"php","python","qna"}){
                Request request = new Request.Builder().
                        url("https://www.v2ex.com/api/nodes/show.json?name="+nodeName).get().build();
                Response response = client.newCall(request).execute();
                V2exNode node = JSON.parseObject(response.body().string(),V2exNode.class);
                assertEquals(node.getName(),nodeName);
            }
        }
    }
  • 相关阅读:
    KMP算法小结
    算法二叉搜索树之AVL树
    算法导论之红黑树的学习
    算法导论小结(一)
    感悟或摘抄
    js中神奇的东西
    简单了解webservice
    用<![CDATA[]]>将xml转义为 纯文本
    简单了解soap协议
    java写webservice接口
  • 原文地址:https://www.cnblogs.com/xinxin1994/p/11260334.html
Copyright © 2011-2022 走看看