2

07-02 测试报告-allure

 2 years ago
source link: https://segmentfault.com/a/1190000040640210
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

07-02 测试报告-allure

allure

  • 轻量级、灵活的、支持多语言的测试报告工具
  • 多平台的、奢华的报告框架
  • 可以为开发、测试提供详尽的测试报告、测试步骤、日志
  • 为管理层提供高规格的统计报告
  • 使用 Java 开发,支持pytest、JavaScript、PHP、Ruby等
  • 可以集成到Jenkins

官网:

allure官网


官方使用文档:

allure 使用文档

Windows / Mac / Linux 通用安装方法:

下载 allure.zip 安装包,解压后配置环境变量即可:

配置路径:allure-2.13.8\bin

allure 官方安装包下载:

allure安装包下载

百度网盘下载:

allure-百度网盘

Mac 命令行安装:

brew install allure 

结合 pytest 使用,需要安装 python 插件:

pip install allure-pytest 

  • 在测试执行期间收集结果:
pytes [测试文件] -s -q --alluredir ./result/  # --alluredir 这个选项用于指定存储测试结果的路径
  • 查看测试报告:

    • 测试完成后查看实际报告,在线查看报告,会直接打开默认浏览器展示当前报告:
allure serve ./result/
  • 从结果生成报告,这是一个启动 tomcat 的服务,包括两步:

    • 生成报告:
allure generate ./result/ -o ./report/ --clean # 覆盖路径需要添加 --clean
  • 打开报告(可远程打开)
allure open -h host -p port ./report/ 

使用场景:在报告中看到测试功能,子功能或场景、测试步骤,包括测试附加信息

使用方法:使用装饰器

  • @allure.feature("功能名称")
@allure.feature("测试采购合同模块")  # 通常对测试类进行装饰
class TestPurchaseContract:
  • @allure.story("子功能/单个用例名称")
@allure.story("测试同步标识灯功能")  # 通常对单个用例进行装饰
def test_synchronize(self):
    """
    测试 同步标识灯 功能
    :return:
    """
    r = self.pending_request.synchronize()
    assert r["msg"] == "同步更新申购单红、绿、蓝灯状态成功"
    assert r["success"] is True
  • @allure.step("步骤细节")
with allure.step("步骤细节"):
    # 具体测试步骤代码
  • @allure.attach("附加信息/日志--可以是数据、文本、图片等")

只运行指定 feature 的用例:

pytest test.py --allure-features="功能名称"

只运行指定 story 的用例:

pytst test.py --allure-stories="子功能/单个用例名称"

结合使用:

pytest test.py --allure-features="功能名称" --allure-stories="子功能/单个用例名称"

allure 特性-testcase

关联测试用例:直接给测试用例的链接地址

test_case_link = "测试用例链接"

@allure.testcase(test_case_link, "描述说明")
def test_with_testcase_link():
    pass

测试报告本地静态数据生成

allure generate ./result -o ./report --clean
# -o:指定报告生成的文件夹
# --clean:先清空测试报告目录,在生成新的测试报告

生成的静态数据,可以使用 tomcat 搭建的web服务中打开

按重要性级别划分测试用例

使用场景:

通常测试有PO、冒烟测试、验证上线测试、回归测试,按重要性级别来分别执行;比如上线要把主流程和重要的模块都跑一遍


用例等级:

  • BLOCKER:阻塞缺陷(功能未实现,无法下一步)
  • CRITICAL:严重缺陷(功能点缺失)
  • NORMAL: 一般缺陷(边界情况,格式错误)
  • MINOR:次要缺陷(界面错误与ui需求不符)
  • TRIVIAL: 轻微缺陷(必须项无提示,或者提示不规范)

使用方法:

# 在方法、函数、类上装饰
@allure.severity(allure.severity_level.TRIVIAL)
def test_with_trivial_severity():
    pass

@allure.severity(allure.severity_level.NORMAL)
def test_with_normal_severity():
    pass

# 执行
pytest -s -v 文件名 --allure-severities normal, critical
pytest -s -v 文件名 --allure-severities=normal, critical

UI自动化测试-截图

使用场景: UI自动化测试经常需要附加图片 / html,在适当的位置进行截图


使用方法:

allure.attach(body, name, attachment_type, extension)
# body:要显示的内容(附件)
# name:附件名字
# attachment_type:附件类型,是 allure.attachment_type 里面的其中一种
# extension:附件的扩展名(比较少用)

allure.attach.file(source, name, attachment_type, extension)
# source:文件路径,相当于传一个文件
# attachment_type提供的附件类型

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK