搭建的API接口自动化测试框架,主要使用 Python中的unittest框架并结合requests模块,采用数据驱动思想(ddt)和分层设计理念,实现测试用例自动化执行。

  • 语言:Python,简洁高效;

  • 测试框架:unittest assertEqual,assertTure,assertFalse:

  • 接口调用:requests,API简洁,提供不同的http请求方法,支持session,cookies;数据驱动:ddt,以用例数据来生成测试用例;

  • 数据管理:openpyxl,进行excel数据的读和写(excel、csv,json,yaml、txt):

  • 数据库交互:pymysql,根据数据库选择相应的第三方模块来完成;。

  • 数据格式的转换:eval,json;

  • 日志处理:logging,统一日志输出格式,渠道,级别,执行结果的记录,便于定位问题;

  • 持续集成:Jenkins,配置定时执行,查看测试通过率,解决重复发版本带来的重复工作(通过插件unittestteport)进行自动构建,生成HTML报告,发送邮件;

把代码安装不同的功能分别放到不同的子文件夹中进行管理,代码分层。

  • 测试用例模块:testcases

  • 测试数据目录:testdata

  • 测试报告目录:reports

  • 公共模块:common

  • 项目入口文件:main.py

│  main.py
│  testcode.py
│
├─common
│  │  read_excel_tool.py
│  │  __init__.py
│  │
│  └─__pycache__
│          read_excel_tool.cpython-39.pyc
│          __init__.cpython-39.pyc
│
├─reports
│      history.json
│      report.html
│
├─testcases
│  │  test_ddt_login.py
│  │  test_some.py
│  │  __init__.py
│  │
│  ├─.pytest_cache
│  │  │  .gitignore
│  │  │  CACHEDIR.TAG
│  │  │  README.md
│  │  │
│  │  └─v
│  │      └─cache
│  │              nodeids
│  │              stepwise
│  │
│  └─__pycache__
│          test_ddt_login.cpython-39.pyc
│          test_some.cpython-39.pyc
│
├─testdata
│      testdata.xlsx
│
└─__pycache__
        testcode.cpython-39.pyc