使用/ EnableCodeCoverage的vstest.console.exe只是“挂起”...如何调试,以及如何修复?

时间:2014-07-01 17:11:03

标签: visual-studio-2012 code-coverage

我正在使用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>

1 个答案:

答案 0 :(得分:14)

我能找到的最终导致解决方案的唯一线索是在事件查看器中,特别是:

.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构建的相当旧的代码。经过大量的搜索,我把它拼凑在一起:

  • vstest.executionengine.exe使用.NET 4配置文件来执行动态代码覆盖检测
  • 事件查看器错误消息是一个模糊的线索,表明vstest.executionengine.exe无法启动.NET 2.0 Profiler
  • 如上所述,修复程序是更新.config(即vstest.executionengine.exe.config)。

将这些内容添加到包含测试的项目的app.config中是不可能的;它必须进入vstest.executionengine的配置(因为这是实际运行的exe)。

我尝试过的其他事情(最终都没有帮助):

注册表中的诊断

Computer\HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\EnterpriseTools\QualityTools\Diagnostics
  • EnableTracing DWORD = 1
  • TraceLevel DWORD = 4

* .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%

Red herring:尝试设置环境变量以禁用

- COR_ENABLE_PROFILING=0
- COMPLUS_ProfAPI_ProfilerCompatibilitySetting=DisableV2Profiler

...试图禁用.NET 2分析器,但什么也没做。

进一步调查(使用procexp.exe)显示,无论env var如何,vstest.executionengine.exe始终设置COR_ENABLE_PROFILING = 1。

此外,COR_PROFILER设置为guid

  • 对我来说,是COR_PROFILER = {B19F184A-CC62-4137-9A6F-AF0F91730165}
  • 通过注册表,HKEY_LOCAL_MACHINE \ SOFTWARE \ Classes \ CLSID {B19F184A-CC62-4137-9A6F-AF0F91730165} \ InprocServer32
  • 对应于&#34; C:\ Program Files(x86)\ Microsoft Visual Studio 11.0 \ Common7 \ IDE \ CommonExtensions \ Microsoft \ IntelliTrace \ 11.0.0 \ x64 \ Microsoft.IntelliTrace.Profiler.11.0.0.dll& #34;

查看事件查看器,我看到了.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&#34; MTM_7d145e0c-1c26-44b0-89e5-acc448aaae6d&#34;不存在。

  • vstest.discoveryengine.TpTrace.log ...错误&#34; AddProcess:无法添加进程5&#34;似乎也无关紧要。

    &#39; System.EventHandler`1 [Microsoft.VisualStudio.TestTools.Execution.SessionStartEventArgs]&#39;到&#39; Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector&#39; I,2800,11,2014 / 07 / 01,10:59:11.875,PCKMA0419 \ vstest.discoveryengine.exe,使用命令行取消注册/通配符/会话启动Vangaurd进程:MTM_ * 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,使用命令行collect / session启动Vangaurd进程:MTM_64f33307-c936-469e-b068-482ec0ea45cf / output:&# 34; 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&#34; /配置:

&#34; C:\用户\ danhaywood \应用程序数据\本地\ TEMP \ MTM_64f33307-c936-469e-b068-482ec0ea45cf \ CodeCoverage.config&#34; ~~~

博客一路咨询: