This Github Action displays test results from popular testing frameworks directly in GitHub.
✔️ Parses test results in XML or JSON format and creates nice report as GitHub Check Run or GitHub Actions job summaries
✔️ Annotates code where it failed based on message and stack trace captured during test execution
✔️ Provides final conclusion
and counts of passed
, failed
and skipped
tests as output parameters
How it looks: |
---|
Supported languages / frameworks:
For more information see Supported formats section.
Do you miss support for your favorite language or framework? Please create Issue or contribute with PR.
Following setup does not work in workflows triggered by pull request from forked repository. If that's fine for you, using this action is as simple as:
on:
pull_request:
push:
permissions:
contents: read
actions: read
checks: write
jobs:
build-test:
name: Build & Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # checkout the repo
- run: npm ci # install packages
- run: npm test # run tests (configured to use jest-junit reporter)
- name: Test Report
uses: dorny/test-reporter@v1
if: success() || failure() # run this step even if previous step failed
with:
name: JEST Tests # Name of the check run which will be created
path: reports/jest-*.xml # Path to test results
reporter: jest-junit # Format of test results
Workflows triggered by pull requests from forked repositories are executed with read-only token and therefore can't create check runs. To workaround this security restriction, it's required to use two separate workflows:
CI
runs in the context of the PR head branch with the read-only token. It executes the tests and uploads test results as a build artifactTest Report
runs in the context of the repository main branch with read/write token. It will download test results and create reportsThe second workflow will only run after it has been merged into your default branch (typically main
or master
), it won't run in a PR unless after the workflow file is part of that branch.
PR head branch: .github/workflows/ci.yml
name: 'CI'
on:
pull_request:
jobs:
build-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4 # checkout the repo
- run: npm ci # install packages
- run: npm test # run tests (configured to use jest-junit reporter)
- uses: actions/upload-artifact@v4 # upload test results
if: success() || failure() # run this step even if previous step failed
with:
name: test-results
path: jest-junit.xml
default branch: .github/workflows/test-report.yml
name: 'Test Report'
on:
workflow_run:
workflows: ['CI'] # runs after CI workflow
types:
- completed
permissions:
contents: read
actions: read
checks: write
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: dorny/test-reporter@v1
with:
artifact: test-results # artifact name
name: JEST Tests # Name of the check run which will be created
path: '*.xml' # Path to test results (inside artifact .zip)
reporter: jest-junit # Format of test results
- uses: dorny/test-reporter@v1
with:
# Name or regex of artifact containing test results
# Regular expression must be enclosed in '/'.
# Values from captured groups will replace occurrences of $N in report name.
# Example:
# artifact: /test-results-(.*)/
# name: 'Test report $1'
# -> Artifact 'test-result-ubuntu' would create report 'Test report ubuntu'
artifact: ''
# Name of the Check Run which will be created
name: ''
# Comma-separated list of paths to test results
# Supports wildcards via [fast-glob](https://github.com/mrmlnc/fast-glob)
# All matched result files must be of the same format
path: ''
# The fast-glob library that is internally used interprets backslashes as escape characters.
# If enabled, all backslashes in provided path will be replaced by forward slashes and act as directory separators.
# It might be useful when path input variable is composed dynamically from existing directory paths on Windows.
path-replace-backslashes: 'false'
# Format of test results. Supported options:
# dart-json
# dotnet-nunit
# dotnet-trx
# flutter-json
# java-junit
# jest-junit
# mocha-json
# rspec-json
reporter: ''
# Allows you to generate only the summary.
# If enabled, the report will contain a table listing each test results file and the number of passed, failed, and skipped tests.
# Detailed listing of test suites and test cases will be skipped.
only-summary: 'false'
# Allows you to generate reports for Actions Summary
# https://github.blog/2022-05-09-supercharging-github-actions-with-job-summaries/
use-actions-summary: 'true'
# Customize the title of badges shown for each Actions Summary.
# Useful when distinguish summaries for tests ran in multiple Actions steps.
badge-title: 'tests'
# Limits which test suites are listed:
# all
# failed
# none
list-suites: 'all'
# Limits which test cases are listed:
# all
# failed
# none
list-tests: 'all'
# Limits number of created annotations with error message and stack trace captured during test execution.
# Must be less or equal to 50.
max-annotations: '10'
# Set action as failed if test report contains any failed test
fail-on-error: 'true'
# Set this action as failed if no test results were found
fail-on-empty: 'true'
# Relative path under $GITHUB_WORKSPACE where the repository was checked out.
working-directory: ''
# Personal access token used to interact with Github API
# Default: ${{ github.token }}
token: ''
Name | Description |
---|---|
conclusion | success or failure |
passed | Count of passed tests |
failed | Count of failed tests |
skipped | Count of skipped tests |
time | Test execution time [ms] |
url | Check run URL |
url_html | Check run URL HTML |
Unfortunately, there are some known issues and limitations caused by GitHub API:
list-suites
and list-tests
will be automatically adjusted if max size is exceeded.actions/upload-artifact@v4
to upload them and inspect them manually.The scripts and documentation in this project are released under the MIT License