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