Minitest Integration with CI Insights
Report your test results from Minitest tests to CI Insights
This guide shows how to generate JUnit reports from your Minitest tests and upload them to CI Insights using a GitHub Actions workflow.
Generate a JUnit Report with Minitest
Section titled Generate a JUnit Report with MinitestMinitest doesn’t have built-in JUnit support, but you can use third-party plugins to generate JUnit XML reports.
Using minitest-junit
Section titled Using minitest-junitInstall the minitest-junit gem:
# Gemfilegroup :test do gem 'minitest-junit'endThen run:
bundle installRequire the gem in your test helper:
require 'minitest/junit'Run tests with JUnit output:
JUNIT_OUTPUT_DIR=. bundle exec ruby -Itest test/**/*_test.rbUsing minitest-reporters
Section titled Using minitest-reportersInstall the minitest-reporters gem which includes JUnit support:
# Gemfilegroup :test do gem 'minitest-reporters'endThen run:
bundle installConfigure it in your test helper:
require 'minitest/reporters'
Minitest::Reporters.use! [ Minitest::Reporters::DefaultReporter.new, Minitest::Reporters::JUnitReporter.new('junit.xml')]Using Rake Task
Section titled Using Rake TaskCreate a Rake task for running tests with JUnit output:
# Rakefilerequire 'rake/testtask'
Rake::TestTask.new(:test_junit) do |t| t.libs << 'test' t.test_files = FileList['test/**/*_test.rb'] ENV['JUNIT_OUTPUT_DIR'] = '.'endThen run:
bundle exec rake test_junitUsing Command Line Configuration
Section titled Using Command Line ConfigurationYou can also run Minitest with JUnit configuration directly:
bundle exec ruby -Itest -rminitest/junit test/**/*_test.rbSet the output directory with environment variable:
JUNIT_OUTPUT_DIR=. bundle exec ruby -Itest -rminitest/junit test/**/*_test.rbUpdate Your GitHub Actions Workflow
Section titled Update Your GitHub Actions WorkflowAfter generating the JUnit report, add a step to upload the results to CI
Insights using the mergifyio/gha-mergify-ci action.
For example, in your workflow file:
- name: Run Minitest Tests and Generate JUnit Report continue-on-error: true env: JUNIT_OUTPUT_DIR: . run: bundle exec ruby -Itest -rminitest/junit test/**/*_test.rb- name: Mergify CI Upload
if: success() || failure()
uses: mergifyio/gha-mergify-ci@v8
with:
token: ${{ secrets.MERGIFY_TOKEN }}
report_path: junit.xml
Key Points:
-
if: success() || failure(): Runs the upload step even if tests fail, ensuring CI Insights has the full report. -
report_path: junit.xml: Points to where your JUnit file is located. Make sure it matches the path you set in your CI job.
Using minitest-reporters approach:
- name: Run Minitest Tests and Generate JUnit Report run: bundle exec rake test- name: Mergify CI Upload
if: success() || failure()
uses: mergifyio/gha-mergify-ci@v8
with:
token: ${{ secrets.MERGIFY_TOKEN }}
report_path: junit.xml
Key Points:
-
if: success() || failure(): Runs the upload step even if tests fail, ensuring CI Insights has the full report. -
report_path: junit.xml: Points to where your JUnit file is located. Make sure it matches the path you set in your CI job.
If you use a job matrix in your workflow (e.g., to test across multiple versions), ensure you set
the job_name input (or MERGIFY_JOB_NAME environment variable) so CI Insights can properly distinguish reports for each matrix job.
For example, with:
jobs:
example_matrix:
strategy:
matrix:
version: [10, 12, 14]
Your upload step should look like:
- name: Mergify CI Upload
if: success() || failure()
uses: mergifyio/gha-mergify-ci@v8
with:
job_name: example_matrix (${{ matrix.version }})
token: ${{ secrets.MERGIFY_TOKEN }}
report_path: junit.xml
In order to benefit from CI Insights Quarantine, you need to add continue-on-error: true
in your GitHb Actions step that execute your tests and generates the JUnit file.
The step running the gha-mergify-ci action will determine the success or failure conclusion,
considering quarantined tests.
Verify and Review in CI Insights
Section titled Verify and Review in CI InsightsAfter pushing these changes:
- Your GitHub Actions workflow will execute your Minitest tests.
- A JUnit report (junit.xml) is generated.
- The Mergify CI action uploads the report to CI Insights.
You can then review your test results, including any failures or flaky tests, directly in the CI Insights dashboard.
Troubleshooting Tips
Section titled Troubleshooting TipsGem Installation: Ensure the chosen JUnit gem (
minitest-junitorminitest-reporters) is properly installed and required.- Environment Variables: Make sure
JUNIT_OUTPUT_DIRis set correctly when using minitest-junit. - The CLI provides information about the upload. Check the logs in GitHub Actions.
- File Paths: Double-check that the output file matches the path used in
report_path. - Permissions: Make sure the
MERGIFY_TOKENis valid and setup in your GitHub Actions secrets as explained in the docs. - Workflow Conditions: If your step is not running, confirm the if condition is actually triggered in your job.
Was this page helpful?
Thanks for your feedback!