1 Star 0 Fork 24

sunnyshare / interface_test_platform

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

BTest platform

前言

BTest是一个接口测试平台, 能帮助用户高效快捷地完成接口自动化用例的开发, 覆盖较为复杂的流程接口场景. 它是我个人业余时间开发的, 难免有不少BUG. 类似这样的平台, 网上已经有很多, 那为什么还要开发这个呢.

在此之前, 实际工作中我基于开源项目HttpRunnerManager做了一些补充性和优化性的二次开发, 渐渐有了自己写个测试平台的想法: 一是为了分享自己的经验和想法,希望能帮助到测试人员更有效的完成工作;二是实践自己的想法, 当是练手.

介绍

本平台基于django restframwork和vue+iview开发, 驱动框架使用httprunner(1.5.8)

强烈建议使用平台前先了解httprunner的基本用法

平台特性

  • 测试管理:按项目-模块-用例的层级管理,均可批量运行用例
  • 用例管理:实现嵌套引用,支持快速调试,以树型展示接口响应数据,并可一键提取结果
  • 定时任务:可编辑任务,树型展示用例,方便选择;支持定时和手动触发任务
  • 测试报告:包括任务概况、用例详情和top10错误表等内容,简洁地展示任务情况
  • 环境管理:保存环境相关的基础数据,便于环境切换,支持python数据类型,支持在线编辑
  • 参数化变量:数据量少时可在用例中定义;数据量大时可在文件中定义,支持在线编辑
  • mock管理:mock数据按接口-场景的层级管理,均支持独立启/禁用
  • 全局变量:方便定义全局通用数据

win开发环境搭建

一、项目结构

  1. 项目结构 BTest接口测试平台20190808.png

  2. 目录说明: 前端代码放在后端代码根目录中 前端目录结构.png 后端目录结构.png

二、前端环境

  1. 安装node.js/npm并配置环境
  2. 配置淘宝镜像
npm install -g cnpm --registry=https://registry.npm.taobao.org
  1. 安装vue脚本架
cnpm install --global vue-cli
  1. cd到frontend目录
cnpm install
  1. 运行前端
npm run dev

三、后端环境

  1. 安装mysql,创建数据库dbname,设置用户名、密码,启动mysql
  2. 修改:AutoTest/settings.py里DATABASES字典和邮件配置
DATABASES = {
        'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'dbname',  # 数据库名
        'USER': 'root',  # 用户名
        'PASSWORD': '123456',  # 密码
        'HOST': '127.0.0.1',  # 数据库ip
        'PORT': '3306',  # 端口默认3306即可
    }
}
EMAIL_SERVER = 'smtp.qq.com' # 邮箱服务器
EMAIL_PORT = 465 # 邮箱服务器端口
EMAIL_SENDER = '123456789@qq.com' # 发件人
EMAIL_PASSWORD = '' # 发件人密码
  1. 安装erlang和rabbitmq,服务是默认启动的,访问地址 http://localhost:15672/
    默认用户名/密码:guest
# 如果没启动使用下面命令
net start RabbitMQ
  1. 安装python3(本人使用3.7,与celery3.x版本存在冲突命名冲突,需要手动修改celery;或者使用py3.6,可以先参考第7点)
  2. 创建虚拟环境(看需要)
python -m venv venvName
venvName/Scripts/activate.bat
  1. 安装三方库
pip install -r require.txt
  1. 更新三方库(celery和httprunner)(必须操作)
# kumbo库中使用了保留关键字async,与python3.7存在冲突,worker无法运行.
考虑下面三种方式:
1.py<=3.6,则不需要修改任务celery相关内容
-----------------------------------------------------------
2.py>=3.7,手动修改kumbo.async包名,再修改celery中相关引用项(未修改运行会报错,挨个改)
-----------------------------------------------------------
3.py>=3.7,命令升级celery库(升到4.x,不确定celery beat任务实时更新是否有效,未验证):
pip install --upgrade https://github.com/celery/celery/tarball/master
-----------------------------------------------------------

# 更新httprunner,把工程根目录下httprunner_update目录的文件全部替换到当前环境三方包httprunner目录下,对1.5.8版本httprunner做了几处优化.
1.引用函数时参数可以使用python多数数据类型 
详情见 https://www.jianshu.com/p/2b83c1216f57
-----------------------------------------------------------
2.结果提取失败可返回用户定义的默认值 
详情见 https://www.jianshu.com/p/c31a803f1f6a
  1. 解压phantomjs, 配置环境变量, 命令行输入phantomjs不报错即可
  2. 安装jdk,为了运行mock服务,如不需要mock服务可跳过
  3. 下载最新版本moco.jar到工程根目录,新命令行切换到工程根目录,运行服务
java -jar moco-runner-X.X.X-standalone.jar http -p 8899 -c mock_data/settings.json
  1. 切换到工程根目录(manage.py所在目录)
python manage.py makemigrations # 生成数据迁移脚本
python manage.py migrate  # 创建表
  1. 启动后端服务(端口自定义,修改后前端也要配置frontend/src/api/index.js)
python manage.py runserver 9999
  1. 新命令行切换到工程根目录, 分别启动worker、beat、flower
celery -A AutoTest worker -l info  #启动worker
celery -A AutoTest beat -l info #启动任务监听
# 上面两命令可以合并: celery -A AutoTest worker -l info -B
celery flower #启动任务后台
  1. 访问:http://localhost:5555/dashboard 即可查看任务列表和状态
  2. 平台地址: http://127.0.0.1:8080/
  3. django后台是否需要看自己情况

功能介绍

  1. 注册新用户,成功后自动登录跳转,前台只能注册为普通用户.而管理员用户可以通过admin后台创建或修改. 1-登录.png

  2. 首页为数据面板,菜单按测试管理-数据管理-报告管理,划为三个模块 2-面板.png

  3. 平台按项目-模块-用例的层级管理,要依次创建对应的条目 3-项目-模块-用例.png

  4. 多数模块都提供了搜索栏 4-搜索栏.png

  5. 项目/模块/用例均提供了批量运行的方式, 而用例也可以单独运行和快速调试 5-运行方式.png

  6. debugtalk页面, 为每个项目绑定一份自定义函数或变量(下版本改为多项目共用debugtalk), 可在线编辑, 遵循python语法. 6-1-debug.png

  7. 用例嵌套引用/快速调试/结果一键提取 7-1-嵌套引用 7-2-快速调试.png 7-3-一键提取.png 7-3-一键提取效果.png 7-4-参数化

  8. 添加及触发任务 8-1-添加任务.png 8-2-运行任务.png

  9. 数据管理, 提供多种形式保存用例数据, 做到数据与用例分离的目的 9-1-数据管理.png

  10. MOCK服务基于moco运行 10-1-新增接口.png 10-2-新增场景.png

  11. 测试报告及邮件 11-1-报告详情.png 11-2-邮件.png

下版本待实现

  1. 增加二级模块; 项目使用目录结构管理(项目-模块-二级模块-用例)
  2. celery分布式并发是以任务为执行单位的,如设定的任务用例数量过大,则无法发布分布式的优势,下版本将对过大的任务进行拆分,可真正发挥分布式并发的优势
  3. 用例重试机制
  4. 任务中错误用例一键重试
  5. 用例草稿/回收站
  6. 自动化文字用例与脚本关联及场景覆盖率统计
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

本平台为接口测试平台, 基于django restframwork和vue+iview开发, 驱动框架使用httprunner 展开 收起
Python
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Python
1
https://gitee.com/Share-Cherish/interface_test_platform.git
git@gitee.com:Share-Cherish/interface_test_platform.git
Share-Cherish
interface_test_platform
interface_test_platform
master

搜索帮助