API自动化测试框架搭建实现过程

自动化测试框架选型首先需要明确测试的目标,同时要考虑测试组成员的技能水平;同时一个好的框架应该是有易用性,可重用性,易维护性和可扩展性

技术准备

语言:Java
框架:Spring,Junit,Cucumber

工具准备

idea,maven,git

开始

  1. 在pom文件中引入依赖包:

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>4.0.0</version>
    </dependency>
    
    org.springframework spring-web ${spring.version}
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.62</version>
    </dependency>
    
    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-api</artifactId>
        <version>2.17.1</version>
    </dependency>
    
  2. 准备好请求报文文件new_product.json
    {
    “color”: “#56ABFB”,
    “members”: [
    “7e7d3bc3fdee474980ac8480b3a01d00”
    ],
    “name”: “测试产品名”,
    “identifier”: “CPMSDAAF”,
    “description”: “des”
    }

  3. 准备feature文件,即测试场景
    Feature: TC01_newProduct01

Scenario Outline: Verify the with the payload
Given call the API with data ,
Then check responseCode and responseMessage
Then Check the data in DB

Examples:
  | Scenario        | Data     |  responseCode     | responseMessage | 
  | new product Scenario | new_product.json | 200 | successful     | 
  1. 实现接口请求发送
    @Given(“call the API with data (["]*),([”]*)")
    public void get_corp_cus(String scenario, String Data, String messageSource) {
    //缺点header,URL,method,然后调用exchang方法发送请求
    responseEntity = restTemplate.exchange(url, HttpMethod.POST, requestEntity, JSONObject.class);
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值