我正在使用vstest.console.exe(VS2012)通过/EnableCodeCoverage和定义了“代码覆盖率” DataCollector的.runsettings运行测试(请参见下面的代码块中的CodeCoverage.runsettings)。
我正在从一个Powershell构建脚本运行,该脚本调用:
vstest.console.exe/inIsolation/Logger:trx/EnableCodeCoverage/Settings:CodeCoverage.runsettings/TestCaseFilter:“TestCategory = Customers” bin\Release\Sdm.Test.IntegTest.dll
以前,此命令有效,但是最近的新项目集成了一些旧的遗留代码,带来了许多新的依赖项/DLL。
我看到的是该命令只是“挂起”,似乎从未运行过任何测试。当我使用SysInternals Process Explorer时,我确实在vstest.executionengine.exe中看到了一些事件……我最大的猜测是,它正在尝试检测我的.runsettings文件中应排除的一整堆DLL。但这只是一个猜测。
在解决如何诊断问题方面的任何帮助将不胜感激。
下面的CodeCoverage.runsettings:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<!-- Configurations that affect the Test Framework -->
<RunConfiguration>
<!-- Path relative to solution directory -->
<ResultsDirectory>.\TestResults</ResultsDirectory>
<!-- [x86] | x64
- You can also change it from menu Test, Test Settings, Default Processor Architecture -->
<TargetPlatform>x64</TargetPlatform>
<!-- Framework35 | [Framework40] | Framework45 -->
<TargetFrameworkVersion>Framework45</TargetFrameworkVersion>
</RunConfiguration>
<!-- Configurations for data collectors -->
<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>
<!--
Additional paths to search for .pdb (symbol) files. Symbols must be found for modules to be instrumented.
If .pdb files are in the same folder as the .dll or .exe files, they are automatically found. Otherwise, specify them here.
Note that searching for symbols increases code coverage runtime. So keep this small and local.
-->
<!--
<SymbolSearchPaths>
<Path>C:\Users\User\Documents\Visual Studio 2012\Projects\ProjectX\bin\Debug</Path>
<Path>\\mybuildshare\builds\ProjectX</Path>
</SymbolSearchPaths>
-->
<!--
About include/exclude lists:
Empty "Include" clauses imply all; empty "Exclude" clauses imply none.
Each element in the list is a regular expression (ECMAScript syntax). See http://msdn.microsoft.com/library/2k3te2cs.aspx.
An item must first match at least one entry in the include list to be included.
Included items must then not match any entries in the exclude list to remain included.
-->
<!-- Match assembly file paths: -->
<ModulePaths>
<Include>
<ModulePath>.*\.dll$</ModulePath>
<ModulePath>.*\.exe$</ModulePath>
</Include>
<Exclude>
<ModulePath>.*CPPUnitTestFramework.*</ModulePath>
<ModulePath>.*[uU]nit[tT]est\.dll</ModulePath>
<ModulePath>.*[iI]nteg[tT]est\.dll</ModulePath>
<ModulePath>.*bomicustomautopoco\.dll</ModulePath>
<ModulePath>.*Common\.Logging\.dll</ModulePath>
<ModulePath>.*Common\.Logging\.Log4Net129.dll</ModulePath>
<ModulePath>.*fluentassertions\.dll</ModulePath>
<ModulePath>.*x509publickeyparser\.dll</ModulePath>
<ModulePath>.*EFCachingProvider\.dll</ModulePath>
<ModulePath>.*EFProviderWrapperToolkit\.dll</ModulePath>
<ModulePath>.*log4net\.dll</ModulePath>
<ModulePath>.*DatahelperDTCBridge\.dll</ModulePath>
<ModulePath>.*\.ni\.dll</ModulePath>
<ModulePath>.*mscorlib\.dll</ModulePath>
<ModulePath>.*vjslib\.dll</ModulePath>
<ModulePath>.*Microsoft\..*dll</ModulePath>
<ModulePath>.*System\.EnterpriseServices\..*dll</ModulePath>
<ModulePath>.*System\.ComponentModel\..*dll</ModulePath>
<ModulePath>.*System\.Configuration\..*dll</ModulePath>
<ModulePath>.*System\.Core\..*dll</ModulePath>
<ModulePath>.*System\.Data\..*dll</ModulePath>
<ModulePath>.*System\.Entity\..*dll</ModulePath>
<ModulePath>.*System\.IdentityModel\..*dll</ModulePath>
<ModulePath>.*System\.Numerics\..*dll</ModulePath>
<ModulePath>.*System\.Runtime\..*dll</ModulePath>
<ModulePath>.*System\.ServiceModel\..*dll</ModulePath>
<ModulePath>.*System\.Transactions\..*dll</ModulePath>
<ModulePath>.*System\.Web\..*dll</ModulePath>
<ModulePath>.*System\.Xml\..*dll</ModulePath>
<ModulePath>.*msdia110typelib_clr0200\.dll</ModulePath>
<ModulePath>.*vstest.executionengine.exe</ModulePath>
<ModulePath>.*BOMi2Service\.dll</ModulePath>
<ModulePath>.*NakedObjects\..*dll</ModulePath>
<ModulePath>.*nakedobjects\..*dll</ModulePath>
<ModulePath>.*sdm\.corejava\.dll</ModulePath>
<ModulePath>.*sdm\.datahelper\.dll</ModulePath>
<ModulePath>.*sdm\.events\.dll</ModulePath>
<ModulePath>.*Sdm\.Infrastructure\.dll</ModulePath>
<ModulePath>.*Sdm\.Infrastructure\.Attributes\.dll</ModulePath>
<ModulePath>.*sdm\.systems\.application\.dll</ModulePath>
<ModulePath>.*sdm\.systems\.distribution\.library\.dll</ModulePath>
<ModulePath>.*sdm\.systems\.distribution\.server\.dll</ModulePath>
<ModulePath>.*sdm\.objectstore\.dll</ModulePath>
<ModulePath>.*sdm\.profiler\.dll</ModulePath>
<ModulePath>.*sdm\.resultsprocessor\.dll</ModulePath>
<ModulePath>.*sdm\.systems\.reflector\.dll</ModulePath>
<ModulePath>.*Sdm\.Test\.Fixtures\.dll</ModulePath>
<ModulePath>.*sdm\.utilities\.dll</ModulePath>
<ModulePath>.*Spring\.Core\.dll</ModulePath>
<ModulePath>.*TechTalk\.SpecFlow\.dll</ModulePath>
</Exclude>
</ModulePaths>
<!-- Match fully qualified names of functions: -->
<!-- (Use "\." to delimit namespaces in C# or Visual Basic, "::" in C++.) -->
<Functions>
<Exclude>
<Function>^Fabrikam\.UnitTest\..*</Function>
<Function>^std::.*</Function>
<Function>^ATL::.*</Function>
<Function>.*::__GetTestMethodInfo.*</Function>
<Function>^Microsoft::VisualStudio::CppCodeCoverageFramework::.*</Function>
<Function>^Microsoft::VisualStudio::CppUnitTestFramework::.*</Function>
</Exclude>
</Functions>
<!-- Match attributes on any code element: -->
<Attributes>
<Exclude>
<!-- Don’t forget "Attribute" at the end of the name -->
<Attribute>^System.Diagnostics.DebuggerHiddenAttribute$</Attribute>
<Attribute>^System.Diagnostics.DebuggerNonUserCodeAttribute$</Attribute>
<Attribute>^System.Runtime.CompilerServices.CompilerGeneratedAttribute$</Attribute>
<Attribute>^System.CodeDom.Compiler.GeneratedCodeAttribute$</Attribute>
<Attribute>^System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute$</Attribute>
</Exclude>
</Attributes>
<!-- Match the path of the source files in which each method is defined: -->
<Sources>
<Exclude>
<Source>.*\\atlmfc\\.*</Source>
<Source>.*\\vctools\\.*</Source>
<Source>.*\\public\\sdk\\.*</Source>
<Source>.*\\microsoft sdks\\.*</Source>
<Source>.*\\vc\\include\\.*</Source>
</Exclude>
</Sources>
<!-- Match the company name property in the assembly: -->
<CompanyNames>
<Exclude>
<CompanyName>.*microsoft.*</CompanyName>
</Exclude>
</CompanyNames>
<!-- Match the public key token of a signed assembly: -->
<PublicKeyTokens>
<!-- Exclude Visual Studio extensions: -->
<Exclude>
<PublicKeyToken>^B77A5C561934E089$</PublicKeyToken>
<PublicKeyToken>^B03F5F7F11D50A3A$</PublicKeyToken>
<PublicKeyToken>^31BF3856AD364E35$</PublicKeyToken>
<PublicKeyToken>^89845DCD8080CC91$</PublicKeyToken>
<PublicKeyToken>^71E9BCE111E9429C$</PublicKeyToken>
<PublicKeyToken>^8F50407C4E9E73B6$</PublicKeyToken>
<PublicKeyToken>^E361AF139669C375$</PublicKeyToken>
</Exclude>
</PublicKeyTokens>
<!-- We recommend you do not change the following values: -->
<UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
<AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
<CollectFromChildProcesses>True</CollectFromChildProcesses>
<CollectAspDotNet>False</CollectAspDotNet>
</CodeCoverage>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
<!-- Adapter Specific sections -->
<!-- MSTest adapter -->
<MSTest>
<MapInconclusiveToFailed>True</MapInconclusiveToFailed>
<CaptureTraceOutput>false</CaptureTraceOutput>
<DeleteDeploymentDirectoryAfterTestRunIsComplete>False</DeleteDeploymentDirectoryAfterTestRunIsComplete>
<DeploymentEnabled>False</DeploymentEnabled>
</MSTest>
</RunSettings>
最佳答案
我能找到的最终导致解决方案的唯一线索是在事件查看器中,特别是:
.NET Runtime version 2.0.50727.5477 - Failed to CoCreate profiler.
最终,这确实使我找到了解决方法,即添加了:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0.30319" />
</startup>
到vstest.executionengine.exe.config(如果运行64位)或vstest.executionengine.x86.exe.config(如果运行32位)。
这在VS(由devenv.exe生成)下和从命令行(由vstest.console.exe生成)下均可使用
以下是使我了解此解决方案的一些注意事项:
所引用的新DLL包括一些针对.NET 2.0构建的相当老的代码。经过大量搜索,我拼凑而成:
如上所述,
无法将这些内容添加到包含测试的项目的app.config中。它必须进入vstest.executionengine的配置中(因为这是实际运行的exe)。
我尝试过的其他方法(最终没有帮助):
注册表中的诊断
Computer\HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\EnterpriseTools\QualityTools\Diagnostics
* .config文件中的诊断
对于vstest.console.exe,vstest.discoveryengine。*。exe,vstest.executionengine。*。exe
C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow
添加:
<system.diagnostics>
<switches>
<add name="TpTraceLevel" value="4" />
</switches>
</system.diagnostics>
...这会导致日志文件写入%TEMP%
红鲱鱼:尝试设置环境变量以禁用
- COR_ENABLE_PROFILING=0
- COMPLUS_ProfAPI_ProfilerCompatibilitySetting=DisableV2Profiler
...试图禁用.NET 2分析器,但未执行任何操作。
进一步调查(使用procexp.exe)显示,与env var无关,vstest.executionengine.exe始终设置COR_ENABLE_PROFILING = 1。
此外,COR_PROFILER设置为guid
通过regedit,HKEY_LOCAL_MACHINE\SOFTWARE\Classes\CLSID {B19F184A-CC62-4137-9A6F-AF0F91730165}\InprocServer32
看着事件查看器,我看到了.NET 4分析器已成功启动的信息消息:
.NET Runtime version 4.0.30319.18063 - The profiler was loaded successfully. Profiler CLSID: '{b19f184a-cc62-4137-9a6f-af0f91730165}'. Process ID (decimal): 7700. Message ID: [0x2507].
%TEMP%中的日志文件也没有提示问题。
红鲱鱼:尝试采用其他方法,并通过env vars启用:
COMPLUS_ProfAPI_ProfilerCompatibilitySetting=EnableV2Profiler
and also explicitly set
COR_PROFILER={B19F184A-CC62-4137-9A6F-AF0F91730165}
也没有什么不同。
其他红鲱鱼
事件查看器中
engine::notify_process_attach失败,发生以下异常: session “MTM_7d145e0c-1c26-44b0-89e5-acc448aaae6d”不存在。
“System.EventHandler`1 [Microsoft.VisualStudio.TestTools.Execution.SessionStartEventArgs]”到“Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector”
I,2800,11,2014/07/01,10:59:11.875,PCKMA0419\vstest.discoveryengine.exe,使用命令行注销/wildcard/session:MTM_ *启动Vangaurd进程
I,2800,11,2014/07/01,10:59:11.880,PCKMA0419\vstest.discoveryengine.exe,将Vangaurd流程添加到项目对象
W,2800,11,2014/07/01,10:59:11.882,PCKMA0419\vstest.discoveryengine.exe,AddProcess:无法添加到AddProcess 5
I,2800,11,2014/07/01,10:59:11.882,PCKMA0419\vstest.discoveryengine.exe,通过命令行启动Vangaurd进程collect/session:MTM_64f33307-c936-469e-b068-482ec0ea45cf/output:“C :\Users\danhaywood\AppData\Local\Temp\MTM_64f33307-c936-469e-b068-482ec0ea45cf\c44e78af-2475-4747-99f3-e0fc3ca41d51\DanHaywood_PCKMA0419 2014-07-01 10_59_11.coverage“/config:
“C:\Users\danhaywood\AppData\Local\Temp\MTM_64f33307-c936-469e-b068-482ec0ea45cf\CodeCoverage.config”
~~~
在此过程中查阅的博客:
关于visual-studio-2012 - 带有/EnableCodeCoverage的vstest.console.exe只是 "hangs"...如何调试,以及如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24515855/