#human-readable #ci #report #turns #messaging #results #slack

bin+lib testvox

将测试报告转换为人类可读消息的库

3 个不稳定版本

0.2.0 2024 年 5 月 24 日
0.1.1 2024 年 5 月 22 日
0.1.0 2024 年 5 月 17 日

#123值格式化

Download history 238/week @ 2024-05-17 135/week @ 2024-05-24 4/week @ 2024-05-31

每月 105 次下载

自定义许可

43KB
921

testvox-logo

Testvox:将测试报告转换为简单、人类可读的摘要

Crates.io Docker

Testvox 是一个小巧的 Rust 库,其目标非常简单:将测试报告转换为人类可读的摘要,以便在常见的消息应用中共享。该项目仅处理报告生成,不关心 发送 这些报告。

目前,它只帮助将 Junit 格式的测试结果转换为 Slack 消息,但我希望在将来添加更多解析器和报告器。

其主要用例可能是 CI 流水线中,尽管它也可以用作 CLI 和库。

在 CI 中使用

目前,仅支持 Github Actions。

作为 Github action 使用

要将此作为 Github action 使用,只需在测试生成后、发送消息前放置以下步骤即可

  steps:

  # ... Steps that generate test results ...

  - uses: dili91/[email protected]
    name: Generate Slack report from Junit results
    # if: always() // might be needed, depending on your pipeline
    id: generate_slack_report
    with:
      include_skipped: true
      reports_pattern: "./test-results/**/*.xml"

  # ... Step that sends the report ...

下面,在 acceptance-test.yml 文件中可以找到完整示例


on: [push]

jobs:
  tests:
    name: Acceptance Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: dili91/[email protected]
        name: Generate Slack report from Junit results
        # if: always() // might be needed, depending on your pipeline
        id: generate_slack_report
        with:
          include_skipped: true
          reports_pattern: "./test-results/**/*.xml"
      - name: Send Slack report
        uses: slackapi/[email protected]
        with:
          payload: ${{steps.generate_slack_report.outputs.report}}
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
          SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

默认配置

该 Github action 有以下要求和默认值

名称 必需 默认值
title ${{github.repository}}test report
reports_pattern ./build/test-results/*.xml
include_skipped false
include_passed false
link ${{github.server_url}}/${{github.repository}}/actions/runs/${{github.run_id}}

作为 CLI 使用

本地安装库

cargo install testvox

然后,从您的终端调用它

testvox --help

Turns test reports into human readable summaries, to be shared on common messaging apps

Usage: testvox [OPTIONS] --title <TITLE>

Options:
  -t, --title <TITLE>
          The title of the test report
  -s, --include-skipped
          Whether to include skipped tests in the report
  -p, --include-passed
          Whether to include passed tests in the report
  -r, --reports-pattern <REPORTS_PATTERN>...
          The test report pattern to look for [default: ./build/test-results/**/*.xml,./app/build/test-results/**/*.xml]
  -h, --help
          Print help

使用 Docker

可选地,您可以使用 Docker 镜像获得相同的功能

docker run --platform=linux/amd64 -v $(PWD):/tmp adilisio/testvox:0.2.0 -p -t "Hello!" -r "/tmp/**/*.xml"


{
  "blocks": [
    {
      "type": "header",
      "text": {
        "type": "plain_text",
        "text": "Hello!",
        "emoji": true
      }
    },
    {
      "type": "divider"
    },
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "✅ _/observe/health endpoint should return 200 and health information_ *passed* (`0.049s`)"
      }
    },
    {
      "type": "divider"
    },
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "✅ _/posts endpoint should return 200 with a list of posts_ *passed* (`0.06s`)"
      }
    },
    {
      "type": "divider"
    },
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "✅ _It should yield a Post mapper_ *passed* (`0.01s`)"
      }
    },
    {
      "type": "divider"
    },
    {
      "type": "section",
      "text": {
        "type": "mrkdwn",
        "text": "✅ _It should convert a raw DbRow object to a Post object_ *passed* (`0.616s`)"
      }
    }
  ]
}

作为库使用

当需要时,Testvox 也可以用作库。您可以通过将crate添加到您的项目来安装它

cargo add testvox

然后,您可以参考其 create_test_report 函数来开始使用它。

依赖项

~3–4.5MB
~106K SLoC