Allure的简单使用,也就是说,Allur


Allure的简单使用

1.Allure简介

简单的理解下,可以把Allure当成一个用于生成美观测试报告的开源工具,配合Pytest测试框架使用更佳。

也就是说,Allure是在Pytest执行测试用例结束后生成的测试数据的基础上,对测试数据进行进一步处理、统计,生成格式统一、美观的测试报告,并通过HTML展示。

2.用例描述

使用方法 参数值 参数说明
@allure.epic() epic描述 定义项目、当有多个项目时使用。
@allure.feature() 模块名称 用例按照模块区分,有多个模块时给每个模块起个名字
@allure.story() 用例名称 对于一个用例的描述
@allure.title() 用例标题 一个用例的标题
@allure.testcase() 测试用例的连接地址 自动化用例对应的功能用例存放系统的路径
@allure.issue() 缺陷地址 对应缺陷管理系统里面的缺陷地址
@allure.description() 用例描述 对测试用例ide详细描述
@allure.step() 操作步骤 测试用例的操作步骤
@allure.severity() 用例等级 blocker\critical\normal\minor\trivial
@allure.link() 定义连接 用于定义一个需要在测试报告中展示的链接
@allure.attachment 附件 添加测试报告附件

3.Pytest集成Allure

Allure要生效需要在测试文件和测试通配文件(conftest.py)中配置Allure,具体见示例项目地址根目录下conftest.py文件

├─api_src 接口与接口串联
│  ├─apis 接口
│  │  └─question 一个功能模块
│  └─process 处理过程
│      └─question
├─data_io
|  ├─allure
|     ├─report 测试报告
│     └─result 结果数据
├─page 页面测试
├─test_case 测试用例
│  └─modules 多模块
│      ├─question 
│      ├─question_batch
│      └─report
├─test_data 测试数据
│  ├─original 原始.har数据
│  └─question yml数据
└─utils 封装的工具类
class TestQuestion(BasicCase):
    @allure.feature("题库管理")
    @allure.story("题目-增查删改")
    @pytest.mark.all
    @pytest.mark.question
    def test_question_add_search_update_delete(self):
        logger.info("==============Case:[题目-增查删改]开始执行==============")
        question_process.question_add_search_update_delete()
        logger.info("==============Case:[题目-增查删改]结束执行==============")

4.生成测试报告

if __name__ == '__main__':
    result_path, report_path = config.allure_report_path()
    test_case = config.get_test_case_path()
	# pytest生成测试报告
    pytest.main(["-vs", test_case, "-m question_batch", "--env=admin", "--isc=False", "--is_vc=True",
                 "--email=False",
                 "-sq", "--alluredir", result_path])
    # allure生成测试报告
    os.system("allure generate {} -o {} --clean ".format(result_path, report_path))
    # 打开测试报告
    os.system("allure open {}".format(config.report_path()))

相关内容

    暂无相关文章

评论关闭