Skip to content

Allure 报告生成

Allure 测试报告

学习价值

学习价值

学习体系

  1. 掌握 Allure 安装与运行方式。
  2. 掌握 Allure 报告生成方式。
  3. 掌握 Allure 报告添加用例信息和附件的写法。

知识模块

  • L1. 安装与运行
  • L2. 用例描述
  • L3. 报告添加附件
  • L4. 报告定制

实战: 将计算器的测试用例和 Allure 报告进行结合

要求添加的报告内容如下:

  • 用例标题
  • 用例描述
  • 修改报告标识

相关知识点

教程地址 教程视频地址 时间范围
Allure2 安装 Allure2 安装 全部
Allure2 运行方式 Allure2 运行方式 全部
Allure2 报告生成 Allure2 报告生成 全部
Allure2 报告中添加用例标题 Allure2 报告中添加用例标题 全部
Allure2 报告中添加用例描述 Allure2 报告中添加用例描述 全部
Allure2 报告定制 Allure2 报告定制 全部

实战代码

@allure.story("计算器")
class TestCalculator:
    @allure.title("范围内的数相加结果正确")
    @allure.description("测试add函数是否能够正确计算两个数的和,且两个数在指定范围内。")
    @pytest.mark.parametrize("a,b,expect", [[1, 2, 3], [99, 99, 198], [90, 90, 180]])
    def test_add_success(self, a, b, expect):
        limit = 99
        res = add(a, b, limit)
        assert res == expect

    @allure.title("范围外的数,错误提示文本正确")
    @allure.description(f"测试add函数是否能验证范围外的数字相加会有对应的错误提示")
    @pytest.mark.parametrize("a,b", [[100, 2], [101, 99], [0, 100]])
    def test_add_fail(self, a, b):
        limit = 99
        res = add(a, b, limit)
        assert res == f"请输入范围为【-{limit}, {limit}】的整数或浮点数"

总结

  • Allure 安装与运行方式。
  • Allure 报告生成方式。
  • Allure 报告添加用例信息和附件的写法。