• Junit5+REST-assured 做接口测试


    1. 先配置maven

     <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-api</artifactId>
                <version>5.6.3</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.junit.jupiter</groupId>
                <artifactId>junit-jupiter-params</artifactId>
                <version>5.7.0</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>io.rest-assured</groupId>
                <artifactId>rest-assured</artifactId>
                <version>3.0.3</version>
            </dependency>
            <dependency>
                <groupId>io.qameta.allure</groupId>
                <artifactId>allure-junit5</artifactId>
                <version>2.13.2</version>
                <scope>test</scope>
            </dependency>

    2.调用企业微信的创建部门接口

    package com.wechat.department;
    
    import io.restassured.response.Response;
    import org.junit.jupiter.api.BeforeAll;
    import org.junit.jupiter.api.DisplayName;
    import org.junit.jupiter.api.Test;
    import org.slf4j.Logger;
    import org.slf4j.LoggerFactory;
    
    import static io.restassured.RestAssured.given;
    
    /**
     * Created by CaiQingYuan on 2021/4/5 17:01
     */
    public class Demo_01_base {
        private static final Logger logger = LoggerFactory.getLogger(Demo_01_base.class);
    
        static String accessToken;
        static int departmentId;
        @BeforeAll
        public static void getAccessToken(){
            accessToken = given().log().all()
                    .when()
                    .param("corpid","*******")
                    .param("corpsecret","******")
                    .get("https://qyapi.weixin.qq.com/cgi-bin/gettoken")
                    .then().log().all()
                    .extract().response().path("access_token");
            logger.info(accessToken);
        }
        @DisplayName("创建部门")
        @Test
        void createDepartment(){
            String body = "{
    " +
                    ""name": "广州研发中心002",
    " +
                    "   "name_en": "RDGZ0002",
    " +
                    "   "parentid": 42,
    " +
                    "   "order": 1,
    " +
                    "   "id": 1006" +
                    "}
    ";
            Response response = given().log().all()
                    .contentType("application/json")
                    .body(body)
                    .post("https://qyapi.weixin.qq.com/cgi-bin/department/create?access_token="+accessToken)
                    .then().log().all()
                    .extract()
                    .response();
            departmentId = response.path("id");
            logger.info(accessToken);
            logger.info(""+departmentId);
        }
    }
  • 相关阅读:
    从汇编看c++中的placement operator new
    从汇编看c++的new和delete
    从汇编看c++中全局对象和全局变量
    javascript中的this
    好工具
    js压缩解压工具
    IE的documentMode属性
    77. sqlserver 锁表解决方式
    75. ID重新走过,备份表
    5. Java中序列化的serialVersionUID作用
  • 原文地址:https://www.cnblogs.com/cythia2018/p/14619039.html
Copyright © 2020-2023  润新知