GitHub Action to publish unit test results on GitHub
GitHub Action to publish unit test results on GitHub
This GitHub Action analyses test result files and publishes the results on GitHub. It supports JSON (Dart, Mocha), TRX (MSTest, VS) and XML (JUnit, NUnit, XUnit) file formats, and runs on Linux, macOS and Windows.
You can use this action with runners (e.g. runs-on: ubuntu-latest)
or self-hosted runners that support Docker:
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: (!cancelled())
with:
files: |
test-results/**/*.xml
test-results/**/*.trx
test-results/**/*.jsonSee the notes on running this action with absolute paths if you cannot use relative test result file paths.
Use this for (e.g. runs-on: macos-latest) runners (no Docker needed):
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/macos@v2
if: (!cancelled())
with:
files: …… and (e.g. runs-on: windows-latest) runners (no Docker needed):
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/windows@v2
if: (!cancelled())
with:
files: …For Windows without PowerShell installed, there is the Bash shell variant:
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/windows/bash@v2
if: (!cancelled())
with:
files: …For self-hosted Linux GitHub Actions runners without Docker installed, please use:
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action/linux@v2
if: (!cancelled())
with:
files: …See the notes on running this action as a non-Docker action.
If you see the "Resource not accessible by integration" error, you have to grant additional permissions, or
setup the support for pull requests from fork repositories and branches created by Dependabot.
The if: (!cancelled()) clause guarantees that this action always runs, even if earlier steps (e.g., the test step) in your workflow fail,
but not if the workflow was cancelled.
When run multiple times in one workflow, the option check_name has to be set to a unique value for each instance.
Otherwise, the multiple runs overwrite each other's results.
Note: By default, this action does not fail if tests failed. This can be configured via action_fail.
The action that executed the tests should fail on test failure. The published results however indicate failure if tests fail or errors occur,
which can be configured via fail_on.
Thanks to the provided typings, it is possible to use this action in a type-safe way using GitHub Workflows Kt, which allows writing workflow files using a type-safe Kotlin DSL.
Minimal workflow job permissions required by this action in public GitHub repositories are:
permissions:
checks: write
pull-requests: writeThe following permissions are required in private GitHub repos:
permissions:
contents: read
issues: read
checks: write
pull-requests: writeWith comment_mode: off, the pull-requests: write permission is not needed.
Supported test result files can be generated by many test environments. Here is a small overview, by far not complete. Check your favorite development and test environment for its JSON, TRX file or JUnit, NUnit, XUnit XML file support.
|Test Environment |Language| JUnit XML | NUnit XML | XUnit XML | TRX file | JSON
file | |-----------------|:------:|:---------:|:---------:|:---------:|:---:|:---:| |Dart|Dart, Flutter| | | | |:white_check_mark:| |Jest|JavaScript|:white_check_mark:| | | | | |Maven|Java, Scala, Kotlin|:white_check_mark:| | | | | |Mocha|JavaScript|:white_check_mark:| |not xunit| |:white_check_mark:| |MStest / dotnet|.Net|:white_check_mark:|:white_check_mark:|:white_check_mark:|:white_check_mark:| | |pytest|Python|:white_check_mark:| | | | | |sbt|Scala|:white_check_mark:| | | | | |Your favorite environment|Your favorite language|probably :white_check_mark:| | | | |
These changes have to be considered when moving from version 1 to version 2:
check_name changedUnless check_name is set in your config, the check name used to publish test results changes from "Unit Test Results" to "Test Results".
Impact: The check with the old name will not be updated once moved to version 2.
Workaround to get version 1 behaviour:
Add check_name: "Unit Test Results" to your config.
comment_title changedUnless comment_title or check_name are set in your config, the title used to comment on open pull requests changes from "Unit Test Results" to "Test Results".
Impact: Existing comments with the old title will not be updated once moved to version 2, but a new comment is created.
Workaround to get version 1 behaviour:
See workaround for check_name.
create new and update last removed for option comment_modeThe action always updates an earlier pull request comment, which is the exact behaviour of mode update last.
The configuration options create new and update last are therefore removed.
Impact: An existing pull request comment is always updated.
Workaround to get version 1 behaviour: Not supported.
hiding_comments removedThe action always updates an earlier pull request comment, so hiding comments is not required anymore.
comment_on_pr removedOption comment_on_pr has been removed.
Workaround to get version 1 behaviour:
Set comment_mode to always (the default) or off.
Test results are published on GitHub at various (configurable) places:
A comment is posted on pull requests related to the commit.
In presence of failures or errors, the comment links to the respective check summary with failure details.
Subsequent runs of the action will update this comment. You can access earlier results in the comment edit history:
The result distinguishes between tests and runs. In some situations, tests run multiple times, e.g. in different environments. Displaying the number of runs allows spotting unexpected changes in the number of runs as well.
When tests run only a single time, no run information is displayed. Results are then shown differently then:
The change statistics (e.g. 5 tests ±0) might sometimes hide test removal. Those are highlighted in pull request comments to easily spot unintended test removal:
Note: This requires check_run_annotations to be set to all tests, skipped tests.
Comments can be disabled with comment_mode: off.
The checks section of a commit and related pull requests list a short summary (here 1 fail, 1 skipped, …),
and a link to the check summary in the GitHub Actions section (here Details):
Commit checks:
Pull request checks:
Check runs can be disabled with check_run: false.
Each failing test produces an annotation with failure details in the checks section of a commit:
and the changed files section of related pull requests:
Note: Annotations for test files are only supported when test file paths in test result files are relative to the repository root.
Use option test_file_prefix to add a prefix to, or remove a prefix from these file paths. See Configuration section for details.
Note: Only the first failure of a test is shown. If you want to see all failures, set report_individual_runs: "true".
Check run annotations can be disabled with ignore_runs: true.
The results are added to the job summary page of the workflow that runs this action:
In presence of failures or errors, the job summary links to the respective check summary with failure details.
Note: Job summary requires GitHub Actions runner v2.288.0 or above.
Job summaries can be disabled with job_summary: false.
Test results are published in the GitHub Actions check summary of the respective commit:
Check runs can be disabled with check_run: false.
The symbols have the following meaning:
| Symbol | Meaning |
|---|---|
| :white_check_mark: | A successful test or run |
| A skipped test or run | |
| A failed test or run | |
| An erroneous test or run | |
| The duration of all tests or runs |
Note: For simplicity, "disabled" tests count towards "skipped" tests.
Files can be selected via the files option. It supports glob wildcards
like *, **, ?, and [] character ranges. The ** wildcard matches all files and directories recursively: ./, ./*/, ./*/*/, etc.
You can provide multiple file patterns, one pattern per line. Patterns starting with ! exclude the matching files.
There have to be at least one pattern starting without a !:
with:
files: |
*.xml
!config.xmlThe list of most notable options:
| Option | Default Value | Description |
|---|---|---|
files |
no default | File patterns of test result files. Relative paths are known to work best, while the non-Docker action also works with absolute paths. Supports *, **, ?, and [] character ranges. Use multiline string for multiple patterns. Patterns starting with ! exclude the matching files. There have to be at least one pattern starting without a !. |
check_name |
"Test Results" |
An alternative name for the check result. Required to be unique for each instance in one workflow. |
comment_title |
same as check_name |
An alternative name for the pull request comment. |
comment_mode |
always |
The action posts comments to pull requests that are associated with the commit. Set to: |
| `a |
No open issues yet, or sync has not completed.