码迷,mamicode.com
首页 > 编程语言 > 详细

十三、postman导出java代码

时间:2019-07-28 19:33:17      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:fastjson   cli   equal   class   tst   depend   postman   实体类   repos   

  • 导出成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);
        }
    }
}

 

十三、postman导出java代码

标签:fastjson   cli   equal   class   tst   depend   postman   实体类   repos   

原文地址:https://www.cnblogs.com/xinxin1994/p/11260334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!