18

私はアセンブリを作成して使用するデモプロジェクトを持っています。私はまた、注入されたコードをデバッグすることができます。しかし、カバレッジ、分析、またはプロファイリングを実行すると、それは数えられますが、私はそれを測定したいと思います。動的に生成されるコードのコードカバレッジ、分析、プロファイリング

コード:

CSharpCodeProvider codeProvider = new CSharpCodeProvider(); 
ICodeCompiler icc = codeProvider.CreateCompiler(); 
CompilerParameters parameters = new CompilerParameters(); 
parameters.GenerateExecutable = false; 
parameters.GenerateInMemory = false; // debug enabled     
parameters.OutputAssembly = "DynamicCode.dll"; // if specified creates the DLL 
parameters.IncludeDebugInformation = true; 
CompilerResults results = icc.CompileAssemblyFromFile(parameters, "InjectedCode.cs.txt"); 

私は、生成されたILコードをチェックするためにDLLを作成します。私はVSでコードをデバッグすることができます。しかし、私がカバレッジを実行すると、生成されたアセンブリは単にTEMPディレクトリを使用する場合、または上記のようにDLLを出力するとNO FILEがカバレッジに含まれます(したがってメインアセンブリでさえも)。

プロファイリングを実行すると、私は呼び出し(リフレクション)しか見ることができませんが、生成されたコードについては何も表示されません。私が分析(私は注射されたコードにいくつかの誤り、例えば、使用されていない地元の人や、すべての人のためのofcの分析がある)、注入されたコードからの問題は報告されません。注入コード:

namespace CodeInjection 
{ 
    public static class DynConcatenateString 
    { 
     public static string Concatenate(string s1, string s2){ 
      // System.Diagnostics.Debugger.Break(); // break here for debugger and also test comment output 
      int a = 1+2+3+4+5; // complicated math 
      int b = a+2; 
      int c = 0; 

      return s1 + " !"+b+"! " + s2; 
     } 
    } 
} 

私は、生成されたコード(主にカバレッジ)に対してカバレッジ、プロファイリングおよび分析を使用したいと考えています。

答えて

1

VS 2012のOkコードカバレッジは、動的に生成されるコードを完全にサポートしていません。

あなたはrun our analyze command、あなたのモジュールは、この非常に同じ理由でスキップされたか、それが原因で不足しているシンボル/ Pプロジェクトで

+0

またスキップしました(コードカバレッジをスキップした後の最初の試行でした)。また、ジェットベインカバーや他のツールミス。今度はトピックの中でさらに深く進んでいきます。次週の結果が期待されますので、ここでお送りします。私の質問は、それが有用かどうかを評価してください。 – cseppento

0

であることがわかり、新しいXMLファイルを追加し、dynamic.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> 
<!-- 
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). 
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. 
It is considered an error to exclude all items from instrumentation as no data would be collected. 
--> 
       <Include> 
       <!-- <ModulePath>.*\\UnitTestProject1\.dll</ModulePath> --> 
       </Include> 
       <Exclude> 
       <ModulePath>.*CPPUnitTestFramework.*</ModulePath> 
       </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:\Users\User\Documents\Visual Studio 11\Projects\ProjectX\bin\Debug</Path> 
    <Path>\\mybuildshare\builds\ProjectX</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>.*\\public\\sdk\\.*</Source> 
       <Source>.*\\microsoft sdks\\.*</Source> 
       <Source>.*\\vc\\include\\.*</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> 

を。このファイルの特別な点は、CodeCoverage \ ModulePaths \ IncludeセクションにModulePathの子がコメントアウトされていることです。これで、コードカバレッジ内で見つかったすべてのDLLが含まれます。

今すぐテスト - >テスト設定 - >テスト設定ファイルを選択をクリックし、dynamic.runsettingsファイルを指定します。コードカバレッジでこのカスタム設定ファイルが使用されるようになりました。

「コードカバレッジの分析」をクリックし、テストを実行します。あなたは(私は以下の私のワークステーション名を隠されている)あなたのDynamicCode.dllがあなたのカバレッジ結果に表示されるはずです。

enter image description here

私は.cs.txtファイルに新しいメソッドを追加しました注BONKと呼ばれますそれは(正確に)100%カバーされていないと表示されます。

関連する問題