Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions .github/skills/trx-analysis/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
name: trx-analysis
description: Parse and analyze Visual Studio TRX test result files. Use when asked about slow tests, test durations, test frequency, flaky tests, failure analysis, or test execution patterns from TRX files.
---

# TRX Test Results Analysis

Parse `.trx` files (Visual Studio Test Results XML) to answer questions about test performance, frequency, failures, and patterns.

## TRX File Format

TRX files use XML namespace `http://microsoft.com/schemas/VisualStudio/TeamTest/2010`. Key elements:

- `TestRun.Results.UnitTestResult` — individual test executions with `testName`, `duration` (HH:mm:ss.fffffff), `outcome` (Passed/Failed/NotExecuted)
- `TestRun.TestDefinitions.UnitTest` — test metadata including class and method info
- `TestRun.ResultSummary` — aggregate pass/fail/skip counts

## Loading a TRX File

```powershell
[xml]$trx = Get-Content "path/to/file.trx"
$results = $trx.TestRun.Results.UnitTestResult
```

## Common Queries

### Top N slowest tests

```powershell
$results | ForEach-Object {
[PSCustomObject]@{
Test = $_.testName
Seconds = [TimeSpan]::Parse($_.duration).TotalSeconds
Outcome = $_.outcome
}
} | Sort-Object Seconds -Descending | Select-Object -First 25 |
Format-Table @{L='Sec';E={'{0,6:N1}' -f $_.Seconds}}, Outcome, Test -AutoSize
```

### Slowest test from each distinct class (top N)

```powershell
$results | ForEach-Object {
$parts = $_.testName -split '\.'
[PSCustomObject]@{
Test = $_.testName
ClassName = ($parts[0..($parts.Length-2)] -join '.')
Seconds = [TimeSpan]::Parse($_.duration).TotalSeconds
}
} | Sort-Object Seconds -Descending |
Group-Object ClassName | ForEach-Object { $_.Group | Select-Object -First 1 } |
Sort-Object Seconds -Descending | Select-Object -First 10 |
Format-Table @{L='Sec';E={'{0,6:N1}' -f $_.Seconds}}, ClassName, Test -AutoSize
```

### Most-executed tests (parameterization frequency)

Extract the base method name before parameterization and count runs:

```powershell
$results | ForEach-Object {
$name = $_.testName
if ($name -match '^(\S+?)[\s(]') { $base = $Matches[1] } else { $base = $name }
[PSCustomObject]@{ Base = $base; Seconds = [TimeSpan]::Parse($_.duration).TotalSeconds }
} | Group-Object Base | ForEach-Object {
[PSCustomObject]@{
Runs = $_.Count
TotalSec = ($_.Group | Measure-Object Seconds -Sum).Sum
Test = $_.Name
}
} | Sort-Object TotalSec -Descending | Select-Object -First 20 |
Format-Table @{L='Runs';E={$_.Runs}}, @{L='TotalSec';E={'{0,7:N1}' -f $_.TotalSec}}, Test -AutoSize
```

### Failed tests

```powershell
$results | Where-Object { $_.outcome -eq 'Failed' } | ForEach-Object {
[PSCustomObject]@{
Test = $_.testName
Seconds = [TimeSpan]::Parse($_.duration).TotalSeconds
Error = $_.Output.ErrorInfo.Message
}
} | Format-Table -Wrap
```

### Summary statistics

```powershell
$summary = $trx.TestRun.ResultSummary.Counters
[PSCustomObject]@{
Total = $summary.total
Passed = $summary.passed
Failed = $summary.failed
Skipped = $summary.notExecuted
Duration = $trx.TestRun.Times.finish
} | Format-List
```

## Tips

- Parameterized tests appear as separate `UnitTestResult` entries. Use regex `'^(\S+?)[\s(]'` to extract the base method name.
- Sort by **TotalSec** (runs × avg duration) to find tests that consume the most CI time overall, even if each individual run is fast.
- TRX files from CI are typically found in `TestResults/` or as pipeline artifacts.
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void HangDumpChildProcesses(RunnerInfo runnerInfo)
var assemblyPaths = GetAssetFullPath("child-hang.dll");
var arguments = PrepareArguments(assemblyPaths, GetTestAdapterPath(), string.Empty, string.Empty, runnerInfo.InIsolationValue);
arguments = string.Concat(arguments, $" /ResultsDirectory:{TempDirectory.Path}");
arguments = string.Concat(arguments, $@" /Blame:""CollectHangDump;HangDumpType=full;TestTimeout=15s""");
arguments = string.Concat(arguments, $@" /Blame:""CollectHangDump;HangDumpType=full;TestTimeout=10s""");
InvokeVsTest(arguments);

ValidateDump(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.IO;

using Microsoft.TestPlatform.TestUtilities;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Microsoft.TestPlatform.AcceptanceTests;
Expand All @@ -26,7 +25,7 @@ public void MSBuildLoggerCanBeEnabledByBuildPropertyAndDoesNotEatSpecialChars(Ru

var projectPath = GetIsolatedTestAsset("TerminalLoggerTestProject.csproj");
// Forcing terminal logger so we can see the output when it is redirected
InvokeDotnetTest($@"{projectPath} -tl:on -nodereuse:false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", workingDirectory: Path.GetDirectoryName(projectPath));
InvokeDotnetTest($@"{projectPath} --no-build -tl:on", workingDirectory: Path.GetDirectoryName(projectPath));

// The output:
// Determining projects to restore...
Expand Down Expand Up @@ -55,7 +54,7 @@ public void MSBuildLoggerCanBeDisabledByBuildProperty(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);

var projectPath = GetIsolatedTestAsset("TerminalLoggerTestProject.csproj");
InvokeDotnetTest($@"{projectPath} -nodereuse:false /p:VsTestUseMSBuildOutput=false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", workingDirectory: Path.GetDirectoryName(projectPath));
InvokeDotnetTest($@"{projectPath} --no-build -nodereuse:false /p:VsTestUseMSBuildOutput=false", workingDirectory: Path.GetDirectoryName(projectPath));

// Check that we see the summary that is printed from the console logger, meaning the new output is disabled.
StdOutputContains("Failed! - Failed: 1, Passed: 1, Skipped: 1, Total: 3, Duration:");
Expand All @@ -75,7 +74,7 @@ public void MSBuildLoggerCanBeDisabledByEnvironmentVariableProperty(RunnerInfo r
SetTestEnvironment(_testEnvironment, runnerInfo);

var projectPath = GetIsolatedTestAsset("TerminalLoggerTestProject.csproj");
InvokeDotnetTest($@"{projectPath} -nodereuse:false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", environmentVariables: new Dictionary<string, string?> { ["MSBUILDENSURESTDOUTFORTASKPROCESSES"] = "1" }, workingDirectory: Path.GetDirectoryName(projectPath));
InvokeDotnetTest($@"{projectPath} --no-build -nodereuse:false", environmentVariables: new Dictionary<string, string?> { ["MSBUILDENSURESTDOUTFORTASKPROCESSES"] = "1" }, workingDirectory: Path.GetDirectoryName(projectPath));

// Check that we see the summary that is printed from the console logger, meaning the new output is disabled.
StdOutputContains("Failed! - Failed: 1, Passed: 1, Skipped: 1, Total: 3, Duration:");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void RunDotnetTestWithCsproj(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);

var projectPath = GetIsolatedTestAsset("SimpleTestProject.csproj");
InvokeDotnetTest($@"{projectPath} -tl:off /p:VSTestNoLogo=false --logger:""Console;Verbosity=normal"" /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", workingDirectory: Path.GetDirectoryName(projectPath));
InvokeDotnetTest($@"{projectPath} --no-build -tl:off /p:VSTestNoLogo=false --logger:""Console;Verbosity=normal""", workingDirectory: Path.GetDirectoryName(projectPath));

// ensure our dev version is used
StdOutputContains(GetFinalVersion(IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion));
Expand All @@ -44,7 +44,7 @@ public void RunDotnetTestWithDll(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);

var assemblyPath = GetAssetFullPath("SimpleTestProject.dll");
InvokeDotnetTest($@"{assemblyPath} --logger:""Console;Verbosity=normal""", workingDirectory: Path.GetDirectoryName(assemblyPath));
InvokeDotnetTest($@"{assemblyPath} --no-build --logger:""Console;Verbosity=normal""", workingDirectory: Path.GetDirectoryName(assemblyPath));

// ensure our dev version is used
StdOutputContains(GetFinalVersion(IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion));
Expand All @@ -61,7 +61,7 @@ public void RunDotnetTestWithCsprojPassInlineSettings(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);

var projectPath = GetIsolatedTestAsset("ParametrizedTestProject.csproj");
InvokeDotnetTest($@"{projectPath} --logger:""Console;Verbosity=normal"" -tl:off /p:VSTestNoLogo=false /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion} -- TestRunParameters.Parameter(name =\""weburl\"", value=\""http://localhost//def\"")", workingDirectory: Path.GetDirectoryName(projectPath));
InvokeDotnetTest($@"{projectPath} --no-build --logger:""Console;Verbosity=normal"" -tl:off /p:VSTestNoLogo=false -- TestRunParameters.Parameter(name =\""weburl\"", value=\""http://localhost//def\"")", workingDirectory: Path.GetDirectoryName(projectPath));

// ensure our dev version is used
StdOutputContains(GetFinalVersion(IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion));
Expand All @@ -78,7 +78,7 @@ public void RunDotnetTestWithDllPassInlineSettings(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);

var assemblyPath = GetAssetFullPath("ParametrizedTestProject.dll");
InvokeDotnetTest($@"{assemblyPath} --logger:""Console;Verbosity=normal"" -- TestRunParameters.Parameter(name=\""weburl\"", value=\""http://localhost//def\"")", workingDirectory: Path.GetDirectoryName(assemblyPath));
InvokeDotnetTest($@"{assemblyPath} --no-build --logger:""Console;Verbosity=normal"" -- TestRunParameters.Parameter(name=\""weburl\"", value=\""http://localhost//def\"")", workingDirectory: Path.GetDirectoryName(assemblyPath));

ValidateSummaryStatus(1, 0, 0);
ExitCodeEquals(0);
Expand All @@ -96,7 +96,7 @@ public void RunDotnetTestWithNativeDll(RunnerInfo runnerInfo)
string assemblyRelativePath = @"microsoft.testplatform.testasset.nativecpp\2.0.0\contentFiles\any\any\x64\Microsoft.TestPlatform.TestAsset.NativeCPP.dll";
var assemblyAbsolutePath = Path.Combine(_testEnvironment.PackageDirectory, assemblyRelativePath);

InvokeDotnetTest($@"{assemblyAbsolutePath} --logger:""Console;Verbosity=normal"" --diag:c:\temp\logscpp\", workingDirectory: Path.GetDirectoryName(assemblyAbsolutePath));
InvokeDotnetTest($@"{assemblyAbsolutePath} --no-build --logger:""Console;Verbosity=normal"" --diag:c:\temp\logscpp\", workingDirectory: Path.GetDirectoryName(assemblyAbsolutePath));

ValidateSummaryStatus(1, 1, 0);
ExitCodeEquals(1);
Expand All @@ -111,7 +111,7 @@ public void RunDotnetTestAndSeeOutputFromConsoleWriteLine(RunnerInfo runnerInfo)
SetTestEnvironment(_testEnvironment, runnerInfo);

var assemblyPath = GetAssetFullPath("OutputtingTestProject.dll");
InvokeDotnetTest($@"{assemblyPath} --logger:""Console;Verbosity=normal"" ", workingDirectory: Path.GetDirectoryName(assemblyPath));
InvokeDotnetTest($@"{assemblyPath} --no-build --logger:""Console;Verbosity=normal""", workingDirectory: Path.GetDirectoryName(assemblyPath));

StdOutputContains("MY OUTPUT FROM TEST");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,15 +512,15 @@ public void RunSettingsAreLoadedFromProject(RunnerInfo runnerInfo)

var projectName = "ProjectFileRunSettingsTestProject.csproj";
var projectPath = GetIsolatedTestAsset(projectName);
InvokeDotnetTest($@"{projectPath} /p:VSTestUseMSBuildOutput=false --logger:""Console;Verbosity=normal"" /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", workingDirectory: Path.GetDirectoryName(projectPath));
InvokeDotnetTest($@"{projectPath} --no-build /p:VSTestUseMSBuildOutput=false --logger:""Console;Verbosity=normal""", workingDirectory: Path.GetDirectoryName(projectPath));
ValidateSummaryStatus(0, 1, 0);

// make sure that we can revert the project settings back by providing a config from command line
// keeping this in the same test, because it is easier to see that we are reverting settings that
// are honored by dotnet test, instead of just using the default, which would produce the same
// result
var settingsPath = GetProjectAssetFullPath(projectName, "inconclusive.runsettings");
InvokeDotnetTest($@"{projectPath} --settings {settingsPath} /p:VSTestUseMSBuildOutput=false --logger:""Console;Verbosity=normal"" /p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion}", workingDirectory: Path.GetDirectoryName(projectPath));
InvokeDotnetTest($@"{projectPath} --no-build --settings {settingsPath} /p:VSTestUseMSBuildOutput=false --logger:""Console;Verbosity=normal""", workingDirectory: Path.GetDirectoryName(projectPath));
ValidateSummaryStatus(0, 0, 1);
}

Expand Down
Loading