的Visual Studio 2012 - 使用.runsettings排除从code覆盖组件组件、Studio、Visual、code

由网友(仙女有对小翅膀)分享简介:在我的解决方案,它包含多个项目运行code覆盖面,我注意到,code覆盖范围还包括我的测试组件。 When running code coverage for my solution which contains multiple projects, I noticed that Code Coverage incl...

在我的解决方案,它包含多个项目运行code覆盖面,我注意到,code覆盖范围还包括我的测试组件。

When running code coverage for my solution which contains multiple projects, I noticed that Code Coverage includes also my test assemblies.

我发现了一篇文章,其中提出以下建议模板.runsettings:

I found an article which suggests the following template for .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>
              <!-- Do not specify any includes. This will attempt to include all binaries -->
            </Include>
            <Exclude>
              <!-- Exclude modules that aren't to be processed, by their name / path -->
          <ModulePath>.*Tests.dll$</ModulePath> <!-- I put it here -->
            </Exclude>
          </ModulePaths>

            <UseVerifiableInstrumentation>True</UseVerifiableInstrumentation>
            <AllowLowIntegrityProcesses>True</AllowLowIntegrityProcesses>
            <CollectFromChildProcesses>True</CollectFromChildProcesses>
            <CollectAspDotNet>False</CollectAspDotNet>
            <!--
Additional paths to search for symbol files. Symbols must be found for modules to be instrumented.
If symbols are alongside the binaries, they are automatically picked up. Otherwise specify the here.
Note that searching for symbols increases code coverage runtime. So keep this small and local.

<SymbolSearchPaths>             
  <Path>C:UsersUserDocumentsVisual Studio 11ProjectsProjectXbinDebug</Path>
  <Path>mybuildsharebuildsProjectX</Path>
</SymbolSearchPaths>
-->
            <Functions>
              <Exclude>
                <Function>^std::.*</Function>
                <Function>^ATL::.*</Function>
                <Function>.*::__GetTestMethodInfo.*</Function>
                <Function>^Microsoft::VisualStudio::CppCodeCoverageFramework::.*</Function>
                <Function>^Microsoft::VisualStudio::CppUnitTestFramework::.*</Function>
                <Function>.*::YOU_CAN_ONLY_DESIGNATE_ONE_.*</Function>
              </Exclude>
            </Functions>
            <Attributes>
              <Exclude>
                <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>
            <Sources>
              <Exclude>
                <Source>.*atlmfc.*</Source>
                <Source>.*vctools.*</Source>
                <Source>.*publicsdk.*</Source>
                <Source>.*microsoft sdks.*</Source>
                <Source>.*vcinclude.*</Source>
              </Exclude>
            </Sources>
            <CompanyNames>
              <Exclude>
                <CompanyName>.*microsoft.*</CompanyName>
              </Exclude>
            </CompanyNames>
            <PublicKeyTokens>
              <Exclude>
                <PublicKeyToken>^B77A5C561934E089$</PublicKeyToken>
                <PublicKeyToken>^B03F5F7F11D50A3A$</PublicKeyToken>
                <PublicKeyToken>^31BF3856AD364E35$</PublicKeyToken>
                <PublicKeyToken>^89845DCD8080CC91$</PublicKeyToken>
                <PublicKeyToken>^71E9BCE111E9429C$</PublicKeyToken>
                <PublicKeyToken>^8F50407C4E9E73B6$</PublicKeyToken>
                <PublicKeyToken>^E361AF139669C375$</PublicKeyToken>
              </Exclude>
            </PublicKeyTokens>
          </CodeCoverage>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

现在的问题是,当我检查我的.runsettings文件中的TEST 测试设置菜单中,我看到了code报导分析只有一个多集在我的解决方案。

Now the problem is that as soon as I check my .runsettings file in the TESTTest settings menu, I see Code Coverage analyzes only one of many assemblies in my solution.

即使我删除行

 <ModulePath>.*Tests.dll$</ModulePath> <!-- I put it here -->

只有一个组件进行分析。我想,以避免增加我所有的组件,以包括列表,我只需要排除所有的测试程序集。

only one assembly is analyzed. I would like to avoid adding all my assemblies to the Include list, I just need to exclude all the test assemblies.

为什么.runsettings使得code覆盖面只看到一个组件在我与解决方案?

推荐答案

问题是周期。出于某种原因,正则表达式是窒息了。你可以解决它通过转义周期如下:

The issue is the period. For some reason the RegEx is choking on that. You can get around it by escaping the period as follows:

<ModulePaths>
    <Include>
        <ModulePath>.*MyCompany.Namespace.Project.dll$</ModulePath>
    </Include>
    <Exclude>
        <ModulePath>.*ThirdParty.Namespace.Project.dll$</ModulePath>
    </Exclude>
</ModulePaths>

另外,空的包括是有效的,并意味着所有模块都包括在内。微软的发表了采样状态是:

Also, the empty includes are valid and imply that all Modules are included. The comments of the Microsoft provided sample state that:

<!--
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.
-->
阅读全文

相关推荐

最新文章