【发布时间】:2019-08-23 06:24:21
【问题描述】:
直到几天前,我一直在使用 OpenCover 来运行我的单元测试并输出代码覆盖率而不会失败。我有一个 powershell 脚本,可以在本地运行,也可以在 Azure DevOps 构建中使用,并且没有任何问题。但现在,OpenCover 不仅仅适用于 Azure DevOps。
我已将我的计算机配置为 Azure DevOps 实例中的构建代理,作为我在本地成功运行 OpenCover 时登录的同一用户作为服务运行。
$info = New-Object System.Diagnostics.ProcessStartInfo
$info.FileName = "C:\Users\devuser\.nuget\packages\opencover\4.6.519\tools\OpenCover.Console.exe"
$info.RedirectStandardError = $true
$info.RedirectStandardOutput = $true
$info.UseShellExecute = $false
$info.Arguments = "`
-target:""C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe"" `
-targetargs:""C:\agent\_work\3\s\UnitTests\bin\Debug\UnitTests.dll"" `
-output:""C:\agent\_work\3\s\opencover.xml"" `
-filter:""+[*]*.Service.* +[*]*.Model.* +[*]*.Repository.*"" `
-excludebyfile:*""*\*Designer.cs"" `
-mergebyhash `
-skipautoprops `
-returntargetcode `
-register:user"
$exec = New-Object System.Diagnostics.Process
$exec.StartInfo = $info
$exec.Start() | Out-Null
$exec.StandardOutput.ReadToEnd() | Out-File -FilePath "C:\agent\_work\3\s\log.txt"
$exec.StandardError.ReadToEnd() | Out-File -FilePath "C:\agent\_work\3\s\log_errors.txt"
在本地运行上述脚本时,我得到了预期的结果:
Executing: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe
Microsoft (R) Test Execution Command Line Tool Version 16.2.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
û GetBookByBookID [636ms]
û SelectBooksByUser [132ms]
û SelectAllBooks [64ms]
û GetBookIDByCoinID [70ms]
û SelectCoinsByBook [79ms]
û PingS3 [922ms]
û GetCoinByCoinID [140ms]
û SelectCoinsBySearch [66ms]
û AddAndRemoveCoin [383ms]
û SelectAllCoins [170ms]
û SelectAllCoinsByBookByUser [135ms]
û SelectOwnedCoinsByBook [128ms]
û SelectAllMintmarks [63ms]
û SelectAllYears [75ms]
û SelectAllDenominations [63ms]
û SelectAllLinkUserCoin [189ms]
û SelectUsers [125ms]
û GetUserNameByUserID [62ms]
û GetUserIDByUserName [69ms]
û SelectUsersByOwned [189ms]
û SelectAllLinkUserBook [67ms]
Test Run Successful.
Total tests: 21
Passed: 21
Total time: 6.0269 Seconds
Committing...
Visited Classes 11 of 11 (100)
Visited Methods 57 of 57 (100)
Visited Points 336 of 336 (100)
Visited Branches 105 of 113 (92.92)
==== Alternative Results (includes all methods including those without corresponding source) ====
Alternative Visited Classes 11 of 11 (100)
Alternative Visited Methods 62 of 62 (100)
但是通过 Azure DevOps 运行完全相同的脚本,我得到了这个:
Executing: C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe
Microsoft (R) Test Execution Command Line Tool Version 16.2.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
√ GetBookByBookID [471ms]
√ SelectBooksByUser [136ms]
√ SelectAllBooks [62ms]
√ GetBookIDByCoinID [62ms]
√ SelectCoinsByBook [66ms]
√ PingS3 [417ms]
√ GetCoinByCoinID [133ms]
√ SelectCoinsBySearch [66ms]
√ AddAndRemoveCoin [413ms]
√ SelectAllCoins [134ms]
√ SelectAllCoinsByBookByUser [142ms]
√ SelectOwnedCoinsByBook [129ms]
√ SelectAllMintmarks [63ms]
√ SelectAllYears [64ms]
√ SelectAllDenominations [61ms]
√ SelectAllLinkUserCoin [148ms]
√ SelectUsers [134ms]
√ GetUserNameByUserID [63ms]
√ GetUserIDByUserName [61ms]
√ SelectUsersByOwned [225ms]
√ SelectAllLinkUserBook [64ms]
Test Run Successful.
Total tests: 21
Passed: 21
Total time: 4.8670 Seconds
Committing...
No results, this could be for a number of reasons. The most common reasons are:
1) missing PDBs for the assemblies that match the filter please review the
output file and refer to the Usage guide (Usage.rtf) about filters.
2) the profiler may not be registered correctly, please refer to the Usage
guide and the -register switch.
我已经搜索了两个建议的原因,但已经在使用
-register:user
显然 pdb 在那里,因为构建配置是 Debug 并且它在本地按预期运行,都在同一个用户下。
有什么建议吗?我不知道 Azure DevOps 上可能有什么不同/缺少什么,以及为什么在成功使用此脚本几个月后会发生这种情况......
【问题讨论】:
标签: c# .net powershell azure-devops opencover