.github/skills/trx-analysis/SKILL.md
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.
npx skillsauth add microsoft/vstest trx-analysisInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Parse .trx files (Visual Studio Test Results XML) to answer questions about test performance, frequency, failures, and patterns.
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 infoTestRun.ResultSummary — aggregate pass/fail/skip counts[xml]$trx = Get-Content "path/to/file.trx"
$results = $trx.TestRun.Results.UnitTestResult
$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
$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
Extract the base method name before parameterization and count runs:
$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
$results | Where-Object { $_.outcome -eq 'Failed' } | ForEach-Object {
[PSCustomObject]@{
Test = $_.testName
Seconds = [TimeSpan]::Parse($_.duration).TotalSeconds
Error = $_.Output.ErrorInfo.Message
}
} | Format-Table -Wrap
$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
Compare two TRX files to find tests that appear in both and ran (were not skipped) in both. Useful for identifying redundant CI work across different configurations (e.g., net9.0 x64 vs net48 x86).
[xml]$trx1 = Get-Content "path/to/file1.trx"
[xml]$trx2 = Get-Content "path/to/file2.trx"
$r1 = $trx1.TestRun.Results.UnitTestResult
$r2 = $trx2.TestRun.Results.UnitTestResult
# Build lookup: testName -> (outcome, duration) keeping best outcome per name
function Get-TestLookup($results) {
$lookup = @{}
foreach ($r in $results) {
$name = $r.testName
$outcome = $r.outcome
$dur = [TimeSpan]::Parse($r.duration)
if (-not $lookup.ContainsKey($name) -or ($lookup[$name].Outcome -eq 'NotExecuted' -and $outcome -ne 'NotExecuted')) {
$lookup[$name] = [PSCustomObject]@{ Outcome = $outcome; Duration = $dur }
}
}
$lookup
}
$t1 = Get-TestLookup $r1
$t2 = Get-TestLookup $r2
$skipped = @('NotExecuted','Pending','Disconnected','Warning','InProgress','Inconclusive')
$common = $t1.Keys | Where-Object { $t2.ContainsKey($_) -and $t1[$_].Outcome -notin $skipped -and $t2[$_].Outcome -notin $skipped }
Parametrized tests contain ( in their name (e.g., RunAllTests (Row: 0, Runner = net10.0, ...)). The base method name is everything before the first (.
$nonParam = $common | Where-Object { $_ -notmatch '\(' }
$param = $common | Where-Object { $_ -match '\(' }
$nonParam | ForEach-Object {
$d1 = $t1[$_].Duration; $d2 = $t2[$_].Duration
[PSCustomObject]@{
Test = $_
File1Sec = $d1.TotalSeconds
File2Sec = $d2.TotalSeconds
TotalSec = $d1.TotalSeconds + $d2.TotalSeconds
}
} | Sort-Object TotalSec -Descending |
Format-Table @{L='File1';E={'{0,6:N1}' -f $_.File1Sec}},
@{L='File2';E={'{0,6:N1}' -f $_.File2Sec}},
@{L='Total';E={'{0,6:N1}' -f $_.TotalSec}}, Test -AutoSize
Tests with (Row: ...) or other parameterization are instances of the same test. Squash them into one row per base method, showing variant count, max single-instance duration, and total duration across all instances in both files.
$param | ForEach-Object {
if ($_ -match '^(.+?)\s*\(') { $base = $Matches[1] } else { $base = $_ }
$d1 = $t1[$_].Duration; $d2 = $t2[$_].Duration
[PSCustomObject]@{ Base = $base; D1 = $d1.TotalSeconds; D2 = $d2.TotalSeconds; Max = [Math]::Max($d1.TotalSeconds, $d2.TotalSeconds) }
} | Group-Object Base | ForEach-Object {
[PSCustomObject]@{
Test = $_.Name
Variants = $_.Count
OneInstance = ($_.Group | Measure-Object Max -Maximum).Maximum
AllInstances = ($_.Group | Measure-Object { $_.D1 + $_.D2 } -Sum).Sum
}
} | Sort-Object AllInstances -Descending |
Format-Table @{L='Variants';E={$_.Variants}},
@{L='1 Instance';E={'{0,7:N1}s' -f $_.OneInstance}},
@{L='All Instances';E={'{0,7:N1}s' -f $_.AllInstances}}, Test -AutoSize
UnitTestResult entries. Use regex '^(\S+?)[\s(]' to extract the base method name.NotExecuted tests — many parameterized tests are skipped in one configuration but not the other, so raw name overlap overstates true duplication.TestResults/ or as pipeline artifacts.development
Best practices for writing MSTest 3.x/4.x unit tests. Use when the user needs to write, improve, fix, or review MSTest tests, including modern assertions, data-driven tests, test lifecycle, and common anti-patterns. Also use when fixing test issues like swapped Assert.AreEqual arguments, incorrect assertion usage, or modernizing legacy test code. Covers MSTest.Sdk, sealed classes, Assert.Throws, DynamicData with ValueTuples, TestContext, and conditional execution.
development
Build, test, and validate changes in the vstest repository. Use when building vstest projects, running unit tests, smoke tests, or acceptance tests, or when deploying locally built vstest.console for manual testing.
development
Validate that commands documented in skill files actually work. Use when creating, updating, or reviewing skills to ensure all documented commands exit with code 0.
development
Quick pragmatic review of .NET test code for anti-patterns that undermine reliability and diagnostic value. Use when asked to review tests, find test problems, check test quality, or audit tests for common mistakes. Catches assertion gaps, flakiness indicators, over-mocking, naming issues, and structural problems with actionable fixes. Use for periodic test code reviews and PR feedback. For a deep formal audit based on academic test smell taxonomy, use exp-test-smell-detection instead. Works with MSTest, xUnit, NUnit, and TUnit.