• HttpRunner3源码阅读: 1. 目录结构分析


    初衷

    身处软件测试行业的各位应该都有耳闻HttpRunner 开源测试工具/框架(接口测试),作者博客

    为什么出这系列?

    1. 不少测试同行都建议阅读HttpRunner,源码学习其设计思想。
    2. 社区当下Python系的接口测试平台多是基于HttpRunner实现
    3. 个人想尝试阅读,并记录希望也能帮到你

    HttpRunner依赖库

    出自: https://github.com/httprunner/httprunner/blob/master/pyproject.toml
    HttpRunner 使用了 poetry库 来进行包管理 和打包的操作

    requests = "^2.22.0"    # 请求库
    pyyaml = "^5.1.2"     # 解析yaml
    jinja2 = "^2.10.3"    # 模板文件,生产测试文件
    pydantic = "^1.4"     # 数据类型定义,类型校验
    loguru = "^0.4.1"     # 日志
    jmespath = "^0.9.5"   # json 提取
    black = "^19.10b0"    # python 代码格式化工具
    pytest = "^5.4.2"     # 单元测试框架
    pytest-html = "^2.1.1"  # 简易html报告
    sentry-sdk = "^0.14.4"  # 没get到xx[好像是版本相关的]
    allure-pytest = "^2.8.16" # allure 报告
    requests-toolbelt = "^0.9.1"  # 估计是上传文件用到的
    filetype = "^1.0.7"   # 文件类型判断
    locust = "^1.0.3"     # 协程实现的性能测试工具 [此次学习不带它]
    Brotli = "^1.0.9"   # 压缩
    

    1. 体验

    # 安装
    pip install httprunner
    
    # 创建项目
    httprunner startproject demo
    
    # 运行项目
    hrun demo
    

    f9UiiF.gif

    最终目录结构

    该系列要阅读的内容

    目录结构分析

    │  cli.py       # 命令封装
    │  client.py    # 请求方法逻辑
    │  compat.py    # 处理testcase格式v2和v3之间的兼容性问题。
    │  exceptions.py  # 自定义异常
    │  loader.py    # 加载文件、环境变量、参数化
    │  make.py      # 生产测试文件
    │  models.py    # pydantic 数据模型定义
    │  parser.py    # 解析自定义语法`$name`,`${func(5)}`
    │  response.py  # 响应内容处理,断言逻辑
    │  runner.py    # 执行/启动器
    │  scaffold.py  # HttpRunner 脚手架
    │  testcase.py  # 测试用例的方法封装
    │  utils.py     # 工具类
    │  __init__.py  # 部分包聚集地
    │  __main__.py  # cli 的 测试启动文件
    │
    ├─app     # FastAPI 应用程序 [可能和官方要出的平台有点关系]
    │  │  main.py
    │  │  __init__.py
    │  │
    │  └─routers
    │     │  debug.py
    │     │  debugtalk.py
    │     │  deps.py
    │     └─__init__.py
    │ 
    ├─builtin
    │  │  comparators.py
    │  │  functions.py
    │  └─__init__.py
    │
    └─ext
       │  __init__.py
       │
       ├─har2case     # har 文件 转 测试用例
       │  │  core.py
       │  │  utils.py
       │  └─__init__.py
       │          
       ├─locust      # 性能测试相关[本次略过]
       │  │  locustfile.py
       │  └─__init__.py
       │
       └─uploader  # 文件上传
          │  
          └─__init__.py
    

    参考资料

    感谢以下内容的作者

    HttpRunner - 李隆 / debugtalk

    HttpRunner3.x中文文档 - 在路上

    微信公众号

    作者:zy7y
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文链接,否则保留追究法律责任的权利。
  • 相关阅读:
    使用MAT 分析内存泄漏实战
    测试面试题集锦----liunx与网络
    Python中request的post请求报requests.exceptions.SSLError:
    python 中requests的返回数可直接使用json
    unittest中的TestLoader使用
    3秒钟unittest入门使用
    postman做接口测试 application/x-www-form-urlencoded 格式与json格式互转
    python读取yaml文件,在unittest中使用
    python 传入任意多个参数(方法调用可传参或不传参)
    boost写的异步客户端样例代码修改为支持断开重连的代码
  • 原文地址:https://www.cnblogs.com/zy7y/p/15090956.html
Copyright © 2020-2023  润新知