听说,有趣的灵魂万里挑一,好看的皮囊千篇一律🙄️,建木 CI + Allure 测试框架真是好看又好用!!
比起 TestNG、ReportNG 自带的测试报告,Allure 框架生成的测试报告颜值大大提升!不过使用时需要安装 Allure 和 Java 环境,稍显繁琐,这里介绍一下如何使用建木 CI 快速生成 Allure 报表文件。
Allure 官网: http://allure.qatools.ru/
Allure 介绍: Allure 框架是一款轻量级,灵活的开源测试报告框架,它支持绝大多数测试框架, 例如 TestNG、Pytest、JUint 等。它简单易用,易于集成。
Allure 界面展示:
前期准备
生成步骤
建木 CI 是通过 建木Hub 节点库中的 allure报表生成节点 来生成 Allure 报表文件的
这里介绍一下 Java 和 Python 项目使用建木 CI 生成 Allure 报表
1.生成 Allure 测试报告数据
使用的示例项目为 Allure 官方提供的示例项目,仓库地址:https://github.com/allure-examples
建木 CI 先通过 git clone节点 获取项目仓库,然后再通过 shell节点 使用不同的工具生成测试报告数据
# clone 项目git_clone:type: git_clone:1.2.0param: remote_url: https://github.com/allure-examples/allure-junit5-maven.git# 通过maven生成Allure测试报告数据maven-test:image: maven:3.8.4-amazoncorretto-8environment: project: ${git_clone.git_path}script: - cd $PROJECT - mvn test
复制代码
# clone 项目git_clone:type: git_clone:1.2.0param: remote_url: https://github.com/allure-examples/allure-python-pytest.git# 通过pytest生成测试报告数据pytest:image: python:3.8-slim-busterenvironment: project: ${git_clone.git_path}script: - cd $PROJECT - pip install allure-pytest || true - pytest --alluredir=allure-results
复制代码
2.生成 Allure 报表
Allure 测试报告数据为 json 数据,为了方便查看和统计,需要使用 allure报表生成节点 来生成 Allure 报表
allure_report:type: allure_report:1.0.1param: # 该路径为生成测试报告数据的文件路径 allure_results_path: ${git_clone.git_path}/allure-results
复制代码
待流程执行完成后,Allure 报表就已经生成完毕了,allure报表生成节点 的输出参数为生成的报表的文件路径
如果你配置了查看 allure-report 报表的服务,接下来可以使用 scp替换文件节点 来替换 allure- report 报表文件
如果你想保存报表文件,也可以使用 七牛云上传 、seafile文件上传 等节点上传到对应的文件服务器中
灵活选择合适的节点,甚至你还可以自定义节点,完成一些自定义功能😃,如何自定义节点
完整 DSL 示例
name: allure-java pipeline: git_clone: type: git_clone:1.2.0 param: remote_url: https://github.com/allure-examples/allure-junit5-maven.git maven-test: image: maven:3.8.4-amazoncorretto-8 environment: project: ${git_clone.git_path} script: - cd $PROJECT - mvn test - ls allure_report: type: allure_report:1.0.1 param: allure_results_path: ${git_clone.git_path}/allure-results
复制代码
name: allure-python pipeline: git_clone: type: git_clone:1.2.0 param: remote_url: https://github.com/allure-examples/allure-python-pytest.git pytest: image: python:3.8-slim-buster environment: project: ${git_clone.git_path} script: - cd $PROJECT - pip install allure-pytest - pytest --alluredir=allure-results || true allure_report: type: allure_report:1.0.1 param: allure_results_path: ${git_clone.git_path}/allure-results
复制代码
本文为 OSCHINA 博主「metting」的原创投稿文章,转载请联系授权。
评论