我有一个包含4个项目的解决方案(2个常规项目和2个测试项目)。我在TFS 2018中有一个构建管道来构建我的解决方案并检查代码覆盖率。我的问题是只报告了一个项目的代码覆盖率。另一个项目的代码覆盖范围丢失。不过,所有测试都在运行。
Visual Studio测试步骤如下:
.runsettings文件的相关部分如下所示:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Configuration>
<CodeCoverage>
<ModulePaths>
<Include>
<ModulePath>.*\.dll$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*CPPUnitTestFramework.*</ModulePath>
<ModulePath>.*moq.dll</ModulePath>
<ModulePath>.*Tests.dll</ModulePath>
</Exclude>
</ModulePaths>
<!-- We recommend you do not change the following values: -->
<UseVerifiableInstrumentation>False</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<CollectAspDotNet>False</CollectAspDotNet>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
这是测试步骤的日志输出:
2018-11-19T13:19:41.2308934Z ## [section]开始:VsTest-netframework
2018-11-19T13:19:41.2412211Z ======================================== ====================================
2018-11-19T13:19:41.2412390Z任务:Visual Studio测试
2018-11-19T13:19:41.2412658Z说明:使用Visual Studio测试运行器运行单元和功能测试(Selenium,Appium,编码的UI测试等)。具有Visual Studio测试适配器的测试框架,例如xUnit,NUnit,Chutzpah等,也可以运行。可以使用此任务(版本2)在多个代理上分发测试。
2018-11-19T13:19:41.2412934Z版本:2.3.28
2018-11-19T13:19:41.2413056Z作者:微软公司
2018-11-19T13:19:41.2413412Z帮助:More Information
2018-11-19T13:19:41.2413616Z ======================================== ====================================
2018-11-19T13:19:42.4501863Z使用vstest.console.exe在本地运行测试
2018-11-19T13:19:42.4502051Z ======================================== ================
2018-11-19T13:19:42.4502460Z测试选择器:测试组件
2018-11-19T13:19:42.4502750Z测试程序集:* * \ release \ * Tests.dll ,! * * \ obj \ * *
2018-11-19T13:19:42.4503062Z测试过滤条件:null
2018-11-19T13:19:42.4503281Z搜索文件夹:C:\ agent_work \ 1 \ s
2018-11-19T13:19:42.4503610Z运行设置文件:C:\ agent_work \ 1 \ s \ MyProject \ CodeCoverage.runsettings
2018-11-19T13:19:42.4503933Z并行运行:false
2018-11-19T13:19:42.4504212Z孤立运行:false
2018-11-19T13:19:42.4505649Z自定义适配器的路径:C:\ agent_work \ 1 \ s \ MyProject \ Project2Tests \ bin \ release
2018-11-19T13:19:42.4505955Z其他控制台选项:null
2018-11-19T13:19:42.4506168Z启用代码覆盖率:false
2018-11-19T13:19:42.4506699Z重新运行失败的测试:假
2018-11-19T13:19:42.8500173Z已选择VisualStudio版本进行测试执行:toolsInstaller
2018-11-19T13:19:43.0554534Z ========================================= ================
2018-11-19T13:19:43.1339450Z [command] C:\ agent_work_tool \ VsTest \ 15.9.1-preview-20181023-04 \ x64 \ tools \ net451 \ Common7 \ IDE \ Extensions \ TestPlatform \ vstest.console.exe @ C:\ WINDOWS \ SERVIC〜3 \ NETWOR〜1 \ AppData \ Local \ Temp \ c6857b51-ebfd-11e8-a1f3-554a7ebf3861.txt
2018-11-19T13:19:43.3385913Z Microsoft(R)Testausführungs-Befehlszeilentool版本15.9.1-preview-20181023-04
2018-11-19T13:19:43.3451743Z版权所有(c)微软公司。 Alle Rechte vorbehalten。
2018-11-19T13:19:43.3452021Z
2018-11-19T13:19:43.3612218Z vstest.console.exe
2018-11-19T13:19:43.3612440Z“ C:\ agent_work \ 1 \ s \ MyProject \ Project1Tests \ bin \ Release \ Project1Tests.dll”
2018-11-19T13:19:43.3612731Z“ C:\ agent_work \ 1 \ s \ MyProject \ Project2Tests \ bin \ Release \ Project2Tests.dll”
2018-11-19T13:19:43.3612945Z /设置:“ C:\ agent_work \ 1 \ s \ MyProject \ CodeCoverage.runsettings”
2018-11-19T13:19:43.3613085Z / logger:“ trx”
2018-11-19T13:19:43.3613289Z / TestAdapterPath:“ C:\ agent_work \ 1 \ s \ MyProject \ Project2Tests \ bin \ release”
2018-11-19T13:19:43.6746135Z死Testausführungwird gestartet,叮咬监狱...
2018-11-19T13:19:44.9662159Z Microsoft(R)Coverage Collection Tool版本15.0.30319.3000
2018-11-19T13:19:44.9663027Z
2018-11-19T13:19:44.9666782Z
2018-11-19T13:19:44.9674700Z版权所有(c)Microsoft Corporation。保留所有权利。
2018-11-19T13:19:44.9677551Z
2018-11-19T13:19:50.3174860Z Bestanden Test1
...很多其他测试...
2018-11-19T13:19:53.3609732Z Microsoft(R)Coverage Collection Tool版本15.0.30319.3000
2018-11-19T13:19:53.3610319Z
2018-11-19T13:19:53.3610430Z
2018-11-19T13:19:53.3610840Z版权所有(c)微软公司。保留所有权利。
2018-11-19T13:19:53.3611590Z
2018-11-19T13:19:53.8607813Z Bestanden Test2
...更多测试...
2018-11-19T13:19:53.9355517Z Ergebnisdatei:C:\ agent_work \ 1 \ s \ TestResults \ TFS-BUILD09 $ _TFS-BUILD09_2018-11-19_14_19_50.trx
2018-11-19T13:19:53.9358179Z
2018-11-19T13:19:53.9451115Z Anlagen:
2018-11-19T13:19:53.9470455Z C:\ agent_work \ 1 \ s \ TestResults \ 332a54cb-163b-4b3b-9bd4-2f5a5be70f4e \ TFS-BUILD09 $ _TFS-BUILD09 2018-11-19 14_19_44.coverage
2018-11-19T13:19:53.9591330Z
2018-11-19T13:19:53.9709295Z测试gesamt:128. Bestanden:128. Fehler:0.Übersprungen:0.
2018-11-19T13:19:53.9741454Z Der Testlauf战争erfolgreich。
2018-11-19T13:19:53.9781474ZTestausführungszeit:8,6925 Sekunden
2018-11-19T13:19:54.2519255Z发布测试结果以测试运行'178'
2018-11-19T13:19:54.2519974Z剩余测试结果:128个。测试运行ID:178
2018-11-19T13:19:54.3272038Z ## [section]异步命令开始:发布测试结果
2018-11-19T13:19:54.6094836Z已发布测试运行:https://xxx/_TestManagement/Runs#runId=178&_a=runCharts
2018-11-19T13:19:54.6095328Z ## [section]异步命令结束:发布测试结果
2018-11-19T13:19:54.6096656Z ## [section]完成:VsTest
答案 0 :(得分:0)
我终于找到了答案。
在.runsettings文件的“包含”部分中,我有以下内容:
<Include>
<ModulePath>.*\.dll$</ModulePath>
</Include>
这意味着仅评估.dll程序集。要同时包含.exe程序集,您必须编写以下内容:
<Include>
<ModulePath>.*\.dll$</ModulePath>
<ModulePath>.*\.exe$</ModulePath>
</Include>