软件测试中,python+requests+pytest+allure+Jenkins框架如何实现
时间: 2023-06-16 10:07:14 浏览: 119
这个框架的实现步骤如下:
1.使用Python编写测试脚本,使用requests库发送HTTP请求并验证响应结果。
2.使用pytest测试框架运行测试脚本,生成测试报告。
3.使用allure测试报告框架对pytest生成的测试报告进行美化和展示。
4.使用Jenkins进行自动化构建和测试,通过配置Jenkins项目,将测试脚本自动集成到Jenkins中。
具体实现步骤如下:
1.安装Python、requests库、pytest框架、allure测试报告框架。
2.编写测试脚本,使用requests库发送HTTP请求并验证响应结果。使用pytest框架运行测试脚本。
3.使用allure测试报告框架对pytest生成的测试报告进行美化和展示,生成测试报告。
4.在Jenkins中创建一个新项目,配置Git仓库地址和构建脚本,将测试脚本自动集成到Jenkins中。
5.在Jenkins中配置邮件通知,当构建失败或测试用例出错时,自动发送邮件通知相关人员。
6.使用Jenkins进行自动化构建和测试。每次代码提交后,Jenkins会自动构建并运行测试脚本,生成测试报告,并将测试报告发送给相关人员。
以上就是python+requests+pytest+allure+Jenkins框架的实现步骤。
相关问题
接口自动化python+requests+pytest+allure+yaml+Jenknis
好的,那我来为您简单介绍一下这些技术的作用和用途,以及它们在接口自动化中的应用。
1. Python:Python是一种高级编程语言,它具有简洁、易读、易维护等特点,因此在接口自动化中得到了广泛应用。
2. Requests:Requests是Python的一个HTTP客户端库,它可以用来发送HTTP请求并处理响应。
3. Pytest:Pytest是Python的一个测试框架,它可以帮助我们编写简洁、优雅的测试代码,并提供了丰富的插件和扩展功能。
4. Allure:Allure是一个测试报告框架,它可以为我们生成美观、易读、易理解的测试报告,并提供了丰富的图表和统计信息。
5. YAML:YAML是一种数据序列化格式,它可以将数据以易读易写的方式表示出来,因此在接口自动化中也得到了广泛应用。
6. Jenkins:Jenkins是一种开源的持续集成工具,它可以自动构建、测试和部署我们的应用程序。
在接口自动化中,我们可以使用Python语言编写测试脚本,使用Requests库发送HTTP请求和处理响应,使用Pytest框架编写测试用例和测试代码,使用Allure框架生成测试报告,使用YAML格式存储测试数据和配置信息,使用Jenkins工具实现自动化构建、测试和部署。
总之,这些技术都是接口自动化中不可或缺的重要组成部分,它们可以帮助我们更加高效、稳定、可靠地进行接口自动化测试。
p2p金融项目,请写出该项目的接口自动化测试代码,使用python+requests+pytest+allure+Jenkins框架的实现步
好的,下面是一个简单的例子:
1. 确认接口地址和参数
首先,我们需要确认接口地址和参数。假设我们要测试的接口地址为 http://localhost:8080/api/register ,需要传递参数 username、password 和 email。其中,username 和 password 是必填项,email 是可选项。
2. 编写测试用例
接下来,我们可以编写测试用例。使用 pytest 框架,我们可以将每个测试用例定义为一个函数。例如,我们可以编写以下测试用例:
```
import requests
import pytest
# 测试注册接口
def test_register():
# 准备测试数据
data = {'username': 'testuser', 'password': 'testpass', 'email': 'testuser@example.com'}
# 发送请求
response = requests.post('http://localhost:8080/api/register', data=data)
# 断言响应结果
assert response.status_code == 200
assert response.json()['success'] == True
# 测试用户名为空的情况
def test_username_empty():
# 准备测试数据
data = {'username': '', 'password': 'testpass', 'email': 'testuser@example.com'}
# 发送请求
response = requests.post('http://localhost:8080/api/register', data=data)
# 断言响应结果
assert response.status_code == 400
assert response.json()['success'] == False
assert 'username' in response.json()['errors']
# 测试密码为空的情况
def test_password_empty():
# 准备测试数据
data = {'username': 'testuser', 'password': '', 'email': 'testuser@example.com'}
# 发送请求
response = requests.post('http://localhost:8080/api/register', data=data)
# 断言响应结果
assert response.status_code == 400
assert response.json()['success'] == False
assert 'password' in response.json()['errors']
```
3. 运行测试用例
我们可以使用 pytest 运行测试用例:
```
pytest test_api.py
```
如果所有测试用例都通过,将会输出类似以下的结果:
```
=========================== test session starts ===========================
platform linux -- Python 3.8.2, pytest-6.2.4, py-1.10.0, pluggy-0.13.1
rootdir: /home/user/projects/p2p
collected 3 items
test_api.py ... [100%]
============================ 3 passed in 0.10s ============================
```
4. 生成 Allure 报告
我们可以使用 Allure 生成漂亮的测试报告。首先,我们需要安装 allure-pytest 插件:
```
pip install allure-pytest
```
接下来,我们可以使用以下命令运行测试用例,并生成 Allure 报告:
```
pytest --alluredir=allure-results
allure serve allure-results
```
打开浏览器,访问 http://localhost:port (port 是生成的端口号),即可查看 Allure 报告。
5. 集成到 Jenkins
最后,我们可以将测试用例集成到 Jenkins 中。首先,我们需要安装 Jenkins 和相关插件。然后,在 Jenkins 中创建一个新的任务,并配置以下步骤:
1. 拉取代码
2. 安装依赖:pytest、requests、allure-pytest
3. 运行测试用例:pytest --alluredir=allure-results
4. 生成 Allure 报告:allure generate allure-results --clean && allure open
配置完成后,每次代码更新后,Jenkins 将会自动运行测试用例,并生成漂亮的 Allure 报告。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)