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

import CommonTroubleshootingTips from "./_common-troubleshooting-tips.mdx"
import GhaMergifyCiQuarantineSetup from "./_gha_mergify_ci_quarantine_setup.mdx"
import MergifyCIUploadStep from "../../../../components/MergifyCIUploadStep.astro"
import MergifyCIUploadStepMatrix from "../../../../components/MergifyCIUploadStepMatrix.astro"
import CIInsightsSetupNote from "../../../../components/CIInsightsSetupNote.astro"

This guide shows how to generate JUnit reports from your MSTest tests and upload
them to **CI Insights** using a GitHub Actions 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 GitHub Actions Workflow

<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
  continue-on-error: true
  run: dotnet test --logger "junit;LogFilePath=junit.xml"
```

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

<GhaMergifyCiQuarantineSetup />

## Verify and Review in CI 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 CI Insights.

You can then review your test results, including any failures or flaky tests,
directly in the [CI Insights
dashboard](https://dashboard.mergify.com/ci-insights/jobs).

## 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>
