eranpeer / FakeIt

C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.
MIT License
1.24k stars 173 forks source link

CodeCoverage reports lines out of range for the test file #221

Open milbrandt opened 3 years ago

milbrandt commented 3 years ago

FakeIt 2.0.5 Build Tools: MSBuild, VSTest, CodeCoverage

I tried to use FakeIt to creat a new unit test with a mock. Language standard is set to stdcpp17.

The file with the test using FakeIt has 104 lines (including commented lines). When I analysed CodeCoverage xml output file I fould several blocks referencing to the file. The first block seems to be ok, all start_lines are in the range of my test method.

But there are additional blocks with line numbers out of range for this file, e.g.

    <function id="1809028" name="LongLongSub" type_name="" block_coverage="0.00" line_coverage="0.00" blocks_covered="0" blocks_not_covered="5" lines_covered="0" lines_partially_covered="0" lines_not_covered="8">
  <ranges>
    <range source_id="52" covered="no" start_line="8204" start_column="0" end_line="8204" end_column="0" />
    <range source_id="52" covered="no" start_line="8206" start_column="0" end_line="8206" end_column="0" />
    <range source_id="52" covered="no" start_line="8215" start_column="0" end_line="8215" end_column="0" />
    <range source_id="52" covered="no" start_line="8219" start_column="0" end_line="8219" end_column="0" />
    <range source_id="52" covered="no" start_line="8221" start_column="0" end_line="8221" end_column="0" />
    <range source_id="52" covered="no" start_line="8224" start_column="0" end_line="8224" end_column="0" />
    <range source_id="52" covered="no" start_line="8227" start_column="0" end_line="8227" end_column="0" />
    <range source_id="52" covered="no" start_line="8228" start_column="0" end_line="8228" end_column="0" />
  </ranges>
</function>

<function id="308992" name="~MethodMockingContextBase&lt;short,unsigned short,short,short,short,iodbpsd *&gt;()" namespace="fakeit" type_name="MockImpl&lt;AbstractDllFanuc&gt;::MethodMockingContextBase&lt;short,unsigned short,short,short,short,iodbpsd *&gt;" block_coverage="0.00" line_coverage="0.00" blocks_covered="0" blocks_not_covered="1" lines_covered="0" lines_partially_covered="0" lines_not_covered="1">
  <ranges>
    <range source_id="52" covered="no" start_line="105" start_column="0" end_line="105" end_column="0" />
  </ranges>
</function>
<function id="309008" name="~MethodMockingContextBase&lt;short,unsigned short,short,short,unsigned short,unsigned short,unsigned short,iodbpmc *&gt;()" namespace="fakeit" type_name="MockImpl&lt;AbstractDllFanuc&gt;::MethodMockingContextBase&lt;short,unsigned short,short,short,unsigned short,unsigned short,unsigned short,iodbpmc *&gt;" block_coverage="0.00" line_coverage="0.00" blocks_covered="0" blocks_not_covered="1" lines_covered="0" lines_partially_covered="0" lines_not_covered="1">
  <ranges>
    <range source_id="52" covered="no" start_line="105" start_column="0" end_line="105" end_column="0" />
  </ranges>
</function>

These lines out of range caused crashes in the subsequent processing of the xml file in my tool chain.

FranckRJ commented 3 years ago

Why do you run the coverage on your tests files ?

milbrandt commented 3 years ago

I want to import the code coverage from Visual Studio to SonarQube/SonarCloud. And there only the xml format is supported. see at sonar.cfamily.vscoveragexml.reportsPath: Note that the .coveragexml report format offered by Visual Studio is not supported.

FranckRJ commented 3 years ago

You should exclude your tests from the code coverage, there is not point of analyzing them : https://docs.microsoft.com/en-us/visualstudio/test/customizing-code-coverage-analysis?view=vs-2019#include-or-exclude-assemblies-and-members

milbrandt commented 3 years ago

The filter of test projects is done on SonarQube side. So it was possible to run the complete CI pipeline without the neeed of a runsettings file.