test-summary / action

Show a helpful summary of test results in GitHub Actions CI/CD workflow runs
MIT License
387 stars 32 forks source link
actions ci-cd github-actions testing

Test Summary

Test dashboard: 42 tests passed Test dashboard: 42 tests failed Test dashboard: 42 tests passed, 8 tests failed, 18 tests skipped

Produce an easy-to-read summary of your project's test data as part of your GitHub Actions CI/CD workflow. This helps you understand at-a-glance the impact to the changes in your pull requests, and see which changes are introducing new problems.

Getting Started

To set up the test summary action, just add a few lines of YAML to your GitHub Actions workflow. For example, if your test harness produces JUnit XML outputs in the test/results/ directory, and you want the output attached to the job summary, add a new step to your workflow YAML after your build and test step:

- name: Test Summary
  uses: test-summary/action@v2
  with:
    paths: "test/results/**/TEST-*.xml"
  if: always()

Update paths to match the test output file(s) that your test harness produces. You can specify glob patterns, including ** to match the pattern recursively. In addition, you can specify multiple test paths on multiple lines. For example:

- name: Test Summary
  uses: test-summary/action@v2
  with:
    paths: |
      test-one/**/TEST-*.xml
      test-two/results/results.tap
  if: always()

Note the if: always() conditional in this workflow step: you should always use this so that the test summary creation step runs even if the previous steps have failed. This allows your test step to fail -- due to failing tests -- but still produce a test summary.

Generating and uploading a markdown file

You can also generate the summary in a GitHub-flavored Markdown (GFM) file, and upload it as a build artifact, add it to a pull request comment, or add it to an issue. Use the output parameter to define the target file.

For example, to create a summary and upload the markdown as a build artifact:

- name: Test Summary
  uses: test-summary/action@v2
  with:
    paths: "test/results/**/TEST-*.xml"
    output: test-summary.md
  if: always()

- name: Upload test summary
  uses: actions/upload-artifact@v3
  with:
    name: test-summary
    path: test-summary.md
  if: always()

Outputs

This action also generates several outputs you can reference in other steps, or even from your job or workflow. These outputs are passed, failed, skipped, and total.

For example, you may want to send a summary to Slack:

- name: Test Summary
  id: test_summary
  uses: test-summary/action@v2
  with:
    paths: "test/results/**/TEST-*.xml"
  if: always()
- name: Notify Slack
  uses: slackapi/slack-github-action@v1.19.0
  with:
    payload: |-
      {
        "message": "${{ steps.test_summary.outputs.passed }}/${{ steps.test_summary.outputs.total }} tests passed"
      }
  if: always()

Examples

There are examples for setting up a GitHub Actions step with many different platforms in the examples repository.

Options

Options are specified on the with map of the action.

FAQ

Questions / Help / Contact

Have questions? Need help? Visit the discussion forum.

Copyright (c) 2022 Edward Thomson. Available under the MIT license.