Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove c__DisplayClass from code coverage

I'm getting c__DisplayClass files appearing in my code coverage analysis that appear to be auto generated code from closures (see this link).

My question is, HOW do you remove this auto generated code from code coverage results?

like image 870
Anthony Avatar asked Jun 22 '26 15:06

Anthony


2 Answers

After some research, I've discovered you can make use of a .runsettings file (documentation).

You can customize your code coverage results within this file like so:

<CodeCoverage>
  <ModulePaths>
    <Exclude></Exclude>
  </ModulePaths>
  <Functions>
    <Exclude>
      <Function>.*c__DisplayClass.*</Function>
    </Exclude>
  </Functions>
</CodeCoverage>

This gave me the results I wanted. All auto generated c__DisplayClass functions are excluded from the results.

like image 197
Anthony Avatar answered Jun 25 '26 05:06

Anthony


Just to add to Anthony's excellent answer, I had lots of auto generated rubbish which can be hidden neatly with the following .runsettings file:

<CodeCoverage>
    <ModulePaths>
        <Exclude></Exclude>
    </ModulePaths>
    <Functions>
        <Exclude>
            <Function>.*&lt;*&gt;.*</Function>
        </Exclude>
    </Functions>
</CodeCoverage>

Note that &lt; and &gt; are the triangular brackets < and > so this should (in my experience) cover all automatically generated code in the coverage results.

like image 33
Rob Kite Avatar answered Jun 25 '26 04:06

Rob Kite