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

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

## Generate a JUnit Report with MSTest

MSTest can generate JUnit-compatible XML reports using the built-in logger or
third-party tools. The `dotnet test` command supports various loggers including
JUnit format.

### Using dotnet test with JUnit Logger

Install the JUnit test logger:

```bash
dotnet add package JunitXml.TestLogger
```

Run tests with JUnit output:

```bash
dotnet test --logger "junit;LogFilePath=junit.xml"
```

### Using TRX to JUnit Conversion

You can also generate TRX files and convert them to JUnit:

```bash
dotnet test --logger trx --results-directory ./TestResults
```

Then use a tool like `trx2junit` to convert:

```bash
dotnet tool install -g trx2junit
trx2junit ./TestResults/*.trx
```

### Using MSTest with Test Results

Add the JUnit logger package to your test project:

```xml
<PackageReference Include="JunitXml.TestLogger" Version="6.1.0" />
```

Then run:

```bash
dotnet test --logger junit
```

### Using Multiple Loggers

You can combine multiple loggers:

```bash
dotnet test --logger "console;verbosity=detailed" --logger "junit;LogFilePath=junit.xml"
```

## Update Your CI Workflow

### GitHub Actions

<CIInsightsSetupNote />

After 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:

```yaml
- name: Run MSTest Tests and Generate JUnit Report
  id: tests
  continue-on-error: true
  run: dotnet test --logger "junit;LogFilePath=junit.xml"
```

<MergifyCIUploadStep reportPath="junit.xml" />
<MergifyCIUploadStepMatrix reportPath="junit.xml" />

<GhaMergifyCiQuarantineSetup />

### Buildkite

<BuildkiteCIUploadStep reportPath="junit.xml" />
<BuildkiteCIUploadStepMatrix reportPath="junit.xml" />

<BuildkiteCIQuarantineSetup />

### Any CI (Mergify CLI)

<MergifyCliUploadStep reportPath="junit.xml" testCommand={`dotnet test --logger "junit;LogFilePath=junit.xml"`} />

## Verify and Review in Test Insights

After pushing these changes:

1. Your GitHub Actions workflow will execute your MSTest tests.
2. A JUnit report (junit.xml) is generated.
3. The Mergify CI action uploads the report to Test Insights.

<ReviewInTestInsights />

## Troubleshooting Tips

<ul>
  <li>Logger Package: Ensure the JunitXml.TestLogger package is added to your test project.</li>
  <li>.NET Version: Make sure you're using a compatible version of .NET that supports the test loggers.</li>

  <CommonTroubleshootingTips />
</ul>
