lauxjpn
lauxjpn

Reputation: 5254

How to only run previously failed tests with dotnet vstest

I have a test suite of over 10,000 tests and sometimes only want to rerun the tests, that failed on the previous run, using the dotnet vstest CLI.

Upvotes: 5

Views: 4674

Answers (1)

lauxjpn
lauxjpn

Reputation: 5254

I ended up using the following PowerShell command, to run only the previously failed tests again, based on the newest trx file in .\TestResults\:

dotnet vstest '.\bin\Debug\netcoreapp3.0\MyTests.dll' /Logger:trx /Tests:"$((Select-Xml -Path (gci '.\TestResults\' | sort LastWriteTime | select -last 1).FullName -XPath "//ns:UnitTestResult[@outcome='Failed']/@testName" -Namespace @{"ns"="http://microsoft.com/schemas/VisualStudio/TeamTest/2010"}).Node.Value | % {$_ -replace '^My\.Long\.And\.Tedious\.Namespace\.', ''} | % {$_ -replace '^(.*?)\(.*$','$1'} | Join-String -Separator ','))"

Beware, that there is a character limit on the maximum command line length, that can easily be hit when many tests have previously failed. Use the % {$_ -replace '^My\.Long\.And\.Tedious\.Namespace\.', ''} part, to get rid of namespace prefixes, if you can.

Upvotes: 5

Related Questions