---
title: Rust Integration with Mergify
description: Report your test results from Rust tests to Mergify
---

<IntegrationLogo src={rustLogo} alt="Rust logo" />

This guide shows how to generate JUnit reports from your Rust tests and upload
them to **Test Engine** using your CI workflow.

## Generate a JUnit Report with Rust Tests

Rust's built-in test framework doesn't output JUnit XML reports. You can either
run your tests through `cargo-nextest`, which writes JUnit XML itself, or keep
`cargo test` and convert its output with `cargo2junit`.

### Using cargo-nextest

`cargo-nextest` is a test runner that writes JUnit XML natively. It has no
command-line flag for it: you enable JUnit output per profile in your
`.config/nextest.toml`.

```bash
cargo install cargo-nextest
```

Add a `junit` section to the profile you use in CI:

```toml
# .config/nextest.toml
[profile.ci.junit]
path = "junit.xml"
```

Then run that profile:

```bash
cargo nextest run --profile ci
```

The `path` is relative to the profile's output directory, so this writes
`target/nextest/ci/junit.xml`.

### Using cargo2junit

`cargo2junit` converts cargo's JSON test output into JUnit XML.

```bash
cargo install cargo2junit
```

It reads that JSON on standard input, so `cargo test` has to be asked for JSON
rather than its usual human-readable output. That option is nightly-only, but
`RUSTC_BOOTSTRAP=1` unlocks it on a stable toolchain:

```bash
RUSTC_BOOTSTRAP=1 cargo test -- -Z unstable-options --format json --report-time | cargo2junit > junit.xml
```

## Update Your CI Workflow

### GitHub Actions

<CIInsightsSetupNote />

After generating the JUnit report, add a step to upload the results to Test
Engine using the `mergifyio/gha-mergify-ci` action.

For example, in your workflow file:

```yaml
- name: Install cargo-nextest
  uses: taiki-e/install-action@nextest

- name: Run Rust Tests and Generate JUnit Report
  id: tests
  continue-on-error: true
  run: cargo nextest run --profile ci
```

<MergifyCIUploadStep reportPath="target/nextest/ci/junit.xml" />
<MergifyCIUploadStepMatrix reportPath="target/nextest/ci/junit.xml" />

Alternative approach using `cargo2junit`, which writes wherever you redirect it:

```yaml
- name: Install cargo2junit
  run: cargo install cargo2junit

- name: Run Rust Tests and Generate JUnit Report
  id: tests
  continue-on-error: true
  run: RUSTC_BOOTSTRAP=1 cargo test -- -Z unstable-options --format json --report-time | cargo2junit > junit.xml
```

<MergifyCIUploadStep reportPath="junit.xml" />

<GhaMergifyCiQuarantineSetup />

### Buildkite

<BuildkiteCIUploadStep reportPath="target/nextest/ci/junit.xml" />
<BuildkiteCIUploadStepMatrix reportPath="target/nextest/ci/junit.xml" />

<BuildkiteTokenNote />

<BuildkiteCIQuarantineSetup />

### Any CI (Mergify CLI)

<MergifyCliUploadStep reportPath="target/nextest/ci/junit.xml" testCommand="cargo nextest run --profile ci" />

## Verify and Review in Test Engine

After pushing these changes:

1. Your GitHub Actions workflow will execute your Rust tests.
2. A JUnit report is generated at `target/nextest/ci/junit.xml`, or wherever you redirect `cargo2junit`.
3. The Mergify CI action uploads the report to Test Engine.

<ReviewInTestInsights />

## Troubleshooting Tips

<ul>
  <li>Tool Installation: Ensure `cargo-nextest` or `cargo2junit` is properly installed before running tests.</li>
  <li>Output Format: Verify that the chosen tool generates valid JUnit XML format.</li>

  <CommonTroubleshootingTips />
</ul>
