如何用建木CI生成Allure报表
2021-12-24 早春的树
如何用建木CI生成Allure报表
作者:早春的树 发布时间:2021-12-24 09:30:00

听说,有趣的灵魂万里挑一,好看的皮囊千篇一律🙄️,建木 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节点 使用不同的工具生成测试报告数据

  • Java项目示例
1
2
3
4
5
6
7
8
9
10
11
12
13
# 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项目示例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 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报表

1
2
3
4
5
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项目

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    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项目

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    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