【问题标题】:How to only run previously failed tests with dotnet vstest如何仅使用 dotnet vstest 运行以前失败的测试
【发布时间】:2020-01-18 17:09:25
【问题描述】:

我有一个包含超过 10,000 个测试的测试套件,有时只想使用 dotnet vstest CLI 重新运行上次运行失败的测试。

【问题讨论】:

    标签: .net-core vstest vstest.console.exe


    【解决方案1】:

    我最终使用了以下 PowerShell 命令,根据.\TestResults\ 中最新的trx 文件再次运行之前失败的测试:

    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 ','))"

    请注意,最大命令行长度有一个字符限制,当许多测试以前失败时很容易达到这个限制。 如果可以的话,使用% {$_ -replace '^My\.Long\.And\.Tedious\.Namespace\.', ''} 部分来去掉命名空间前缀。

    【讨论】:

    • !!!你刚刚为我节省了很多时间!!! xUnit 的 NET5 命令看起来会略有不同,例如:...
    • dotnet test .\MyUnitTests\bin\Debug\net5.0\MyUnitTests.dll --logger "trx;LogFileName=MyUnitTests_01.xml" --results-directory .\TestResults --logger "console;verbosity=minimal" --filter ("DisplayName~" + ((Select-Xml -Path .\TestResults\MyUnitTests.xml -XPath "//ns:UnitTestResult[@outcome='Failed']/@testName" -Namespace @{"ns"="http://microsoft.com/schemas/VisualStudio/TeamTest/2010"}).Node.Value | % {$_ -replace '^MyUnitTests\.', ''} | % {$_ -replace '^(.*?)\(.*$','$1'} | Join-String -Separator ' | DisplayName~'))
    猜你喜欢
    • 2023-02-15
    • 2015-11-20
    • 2018-07-26
    • 2021-10-27
    • 2023-03-12
    • 2020-12-14
    • 1970-01-01
    • 2016-04-16
    • 2016-10-11
    相关资源
    最近更新 更多