πŸ’ΈSave up to $132K/month in CI costs!πŸ‘‰ Try Free✨
Skip to main content
← Back to workflows

How to Publish Test Results with GitHub Actions

EnricoMi-publish-unit-test-result-action -
GitHub Action
v2.17.1
608
Contributors
Contributor - EnricoMiContributor - lachaib
Categories

Optimize Your CI/CD Pipeline

Get instant insights into your CI/CD performance and costs. Reduce build times by up to 45% and save on infrastructure costs.

45% Faster Builds
60% Cost Reduction
Usage
name: Publish Test Results
on:
push:
branches:
- main

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Run Tests
run: npm test
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: always()
with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.json

publish-unit-test-result-action logo

publish-unit-test-result-action

This action analyzes test result files and publishes the results on GitHub, supporting JSON, TRX, and XML formats.


What is publish-unit-test-result-action?​

The publish-unit-test-result-action is a GitHub Action that publishes test results from your CI/CD pipelines to GitHub. It supports various test result file formats like JSON, TRX, and XML (JUnit, NUnit, XUnit) and can run on multiple platforms including Linux, macOS, and Windows.

How to Use with Different Runners​

Here’s how to configure the action based on the OS runner you’re using:

For Linux:

with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.json

For macOS:

uses: EnricoMi/publish-unit-test-result-action/macos@v2
with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.json

For Windows:

uses: EnricoMi/publish-unit-test-result-action/windows@v2
with:
files: |
test-results\**\*.xml
test-results\**\*.trx
test-results\**\*.json

How to Handle Large Files​

If your test result files are large, you can enable large file support by setting the large_files option to true:

with:
large_files: true

How to Configure Pull Request Comments​

To automatically post comments on related pull requests based on the test results, use the comment_mode option. For example, to comment only when test failures occur:

with:
comment_mode: failures

To disable comments entirely:

with:
comment_mode: off

How to Configure files​

The files option specifies the test result files to be processed. You can use glob patterns to match multiple files:

with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.json

How to Set a Unique check_name​

When running the action multiple times in one workflow, set a unique check_name to prevent results from overwriting each other:

with:
check_name: "My Test Results"

How to Ignore Test Runs Information​

If your test result files are very large, you can ignore run details by using the ignore_runs option:

with:
ignore_runs: true

How to Configure GitHub Permissions​

In private repositories, you may need to configure permissions to allow the action to work properly. Here’s an example of how to set permissions:

permissions:
contents: read
issues: read
checks: write
pull-requests: write

How to Set report_individual_runs​

To see all failures instead of just the first one, enable the report_individual_runs option:

with:
report_individual_runs: true

How to Disable Check Runs​

If you do not want to create check runs, disable them by setting check_run to false:

with:
check_run: false

How to Generate Test Result Files​

Supported test result formats can be generated by various testing frameworks and environments. Here are a few examples:

Test EnvironmentLanguageJUnit XMLNUnit XMLXUnit XMLTRX FileJSON File
DartDart, Flutterβœ…
JestJavaScriptβœ…
MavenJava, Scala, Kotlinβœ…
MochaJavaScriptβœ…βœ…
MSTest / dotnet.Netβœ…βœ…βœ…βœ…
pytestPythonβœ…
sbtScalaβœ…

Check your development environment for support for these formats or generate them using compatible plugins.

How to Use with Matrix Strategy​

If your tests run in different environments using a matrix strategy, the action should run only once over all test results. Here’s an example:

jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- run: npm test
- name: Upload test results
uses: actions/upload-artifact@v2
with:
name: test-results
path: test-results/

publish:
needs: test
runs-on: ubuntu-latest
steps:
- uses: actions/download-artifact@v2
with:
name: test-results
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.json

How to Access Test Results as JSON​

You can also access test results as JSON via the action's outputs or save them as a file. Here’s an example to access the JSON output:

steps:
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: |
test-results/**/*.xml
id: test_results

- name: Access Test Results JSON
run: echo "${{ steps.test_results.outputs.json }}"

This can be used to create a badge or further process the results.