2021.2.28接口测试前沿技术

1. 掌握的知识点

  • 接口diff测试
  • rpc协议
  • 自动生成接口测试用例代码
  • 接口测试结构化分析

2. 需要准备的环境

diffy
https://github.com/opendiffy/diffy 16

dubbo

Apache Dubbo 8

Apache Dubbo 9

Apache Dubbo 官方网站

 

pb
https://developers.google.com/protocol-buffers 6

mitmproxy

docs.mitmproxy.org 3

Introduction 4

作用:当网站需要重构时,新老版本的接口发生了哪些变化

3.1 diff安装
  gitbash里clone源码:git clone git@github.com/opendiffy/diffy.git
  可能会报错:   fatal: unable to access 'https://github.com/opendiffy/diffy.git/': OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443,  进入github.com:443页面,登陆进去后再执行clone,成功
  cd diff目录, 然后执行 

  ./sbt assembly  -------编译成一个jar包

   bash -x ./example/run.sh start

3.2 查看对比结果

4. YAPI

 

 

 

4. 服务端的API管理

https://github.com/YMFE/yapi 1

editor.swagger.io

Swagger Editor 

4.1 api规范

/pet/findByStatus:
    get:
      tags:
      - "pet"
      summary: "Finds Pets by status"
      description: "Multiple status values can be provided with comma separated strings"
      operationId: "findPetsByStatus"
      produces:
      - "application/xml"
      - "application/json"
      parameters:
      - name: "status"
        in: "query"
        description: "Status values that need to be considered for filter"
        required: true
        type: "array"
        items:
          type: "string"
          enum:
          - "available"
          - "pending"
          - "sold"
          - "hogwarts"
          default: "available"
        collectionFormat: "multi"
      responses:
        200:
          description: "successful operation"
          schema:
            type: "array"
            items:
              $ref: "#/definitions/Pet"
        400:
          description: "Invalid status value"
      security:
      - petstore_auth:
        - "write:pets"
        - "read:pets"

生成stub,方便前后端开发与QA的联调。
一个基于spring的接口stub代码

    @ApiOperation(value = "Finds Pets by status", nickname = "findPetsByStatus", notes = "Multiple status values can be provided with comma separated strings", response = Pet.class, responseContainer = "List", authorizations = {
        @Authorization(value = "petstore_auth", scopes = {
            @AuthorizationScope(scope = "write:pets", description = "modify pets in your account"),
            @AuthorizationScope(scope = "read:pets", description = "read your pets")
            })
    }, tags={ "pet", })
    @ApiResponses(value = { 
        @ApiResponse(code = 200, message = "successful operation", response = Pet.class, responseContainer = "List"),
        @ApiResponse(code = 400, message = "Invalid status value") })
    @RequestMapping(value = "/pet/findByStatus",
        produces = { "application/xml", "application/json" }, 
        method = RequestMethod.GET)
    ResponseEntity<List<Pet>> findPetsByStatus(@NotNull @ApiParam(value = "Status values that need to be considered for filter", required = true, allowableValues = "available, pending, sold, hogwarts") @Valid @RequestParam(value = "status", required = true) List<String> status);

生成client sdk,一个是给QA生成接口测试用例,一个是给后端的人提供一个调用的sdk

    /**
     * Finds Pets by status
     *
     * Multiple status values can be provided with comma separated strings
     *
     * @throws ApiException
     *          if the Api call fails
     */
    @Test
    public void findPetsByStatusTest() throws ApiException {
        List<String> status = Arrays.asList("sold");
        List<Pet> response = api.findPetsByStatus(status);
        assertEquals(response.get(0).getName() , "xx");

        // TODO: test validations
    }

MockServer与Mock相关的概念

 

因为这个文章比较好,转到测试人社区内方便大家学习参考。原始链接 https://testing.googleblog.com/2020/11/fixing-test-hourglass.html Fixing a Test Hourglass Monday, November 09, 2020 By Alan Myrvold Automated tests make it safer a…

 

 

 

服务端的测试用例生成

mustache模板技术

mustache.github.io

{{ mustache }}

 

https://github.com/swagger-api/swagger-codegen

java测试用例生成
https://github.com/swagger-api/swagger-codegen/tree/master/modules/swagger-codegen/src/main/resources/Java

流量复制与Diff测试

网络协议层的请求构造工具
https://github.com/buger/goreplay

代理层面的twitter diffy
https://github.com/opendiffy/diffy

hook层的请求构造工具
https://github.com/alibaba/jvm-sandbox-repeater

 

 

RPC协议的测试

rpc测试用例结构

  • page/api object模式的定义接口文件(po的接口定义) PetApiInterface
  • po方法具体实现(http rpc) PetApiRPCImplemented PetApiImplemented
  • 测试用例文件 PetApiTest

https://developers.google.com/protocol-buffers/docs/javatutorial

https://github.com/apache/thrift/tree/master/tutorial/java

RPC:可以基于不同的协议实现, 比如http、json rpc、tcp、udp协议实现。最后调用的时候是协议透明,只需要调用特定语言的sdk就可以。

 

posted @ 2021-02-28 15:27  方园FPP  阅读(283)  评论(0编辑  收藏  举报