• 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# 实现串口拨号器的SIM卡通信
    物联网协议Coap协议介绍
    C#实现简单的串口通信
    C#硬件访问(摄像头、麦克风)
    请问在电脑里PNP是什么意思啊?
    原码,反码,补码,及Java中数字表示方法
    3_PHP表达式_5_数据类型转换_类型强制转换
    3_PHP表达式_4_PHP运算符
    3_PHP表达式_5_数据类型转换_类型自动转换
    3_PHP表达式_3_有关变量或常量状态的函数
  • 原文地址:https://www.cnblogs.com/cythia2018/p/14619039.html
Copyright © 2020-2023  润新知