Inconsistent coverage results using dotCover console runner with .NET Core unit tests.

Symptoms

The assemblies you are trying to cover have 0% coverage.

 

Possible cause

When covering "dotnet test" or "dotnet vstest" dotCover might get 0% coverage because the process with tests was killed by test platform before dotCover has a chance to save a snapshot.

 

Workaround

dotCover console runner:

  • You have a Windows machine with installed dotCover 2018.1.1 or later.
  • You have a .NET Core unit test project.
  • You want to perform coverage analysis of unit tests via the command line.

 

To perform coverage analysis:

  1. Create (or modify an existing) a .runsettings file for the project, e.g. mySettings.runsettings.
  2. Modify the file based on the example below

    <?xml version="1.0" encoding="utf-8"?>  
    <RunSettings>
     <RunConfiguration>
       <DisableParallelization>True</DisableParallelization>
     </RunConfiguration>
     <InProcDataCollectionRunSettings>
       <InProcDataCollectors>
         <InProcDataCollector friendlyName="JetBrainsProfiler" uri="InProcDataCollector://JetBrains/JetBrainsProfiler/1.0" assemblyQualifiedName="<AQN>" codebase="<PATH>">
           <Configuration />
         </InProcDataCollector>
       </InProcDataCollectors>
     </InProcDataCollectionRunSettings>
    </RunSettings>

    Here
    • <AQN>: an assembly qualified name that depends on a dotCover version. For dotCover 2018.1.1, it is: JetBrains.Common.UnitTesting.InProcDataCollector.GrouplessCoverageInProcDataCollector, JetBrains.Common.UnitTesting.InProcDataCollector, Version=112.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325
    • <PATH>: an absolute path to the JetBrains.Common.UnitTesting.InProcDataCollector.dll library which is a part of dotCover. For example:
      C:\Users\[YourUserName]\AppData\Local\JetBrains\Installations/JetBrains/Installations/dotCover12/JetBrains.Common.UnitTesting.InProcDataCollector.dll

  3. Run coverage analysis from the command line with the additional /UseApi parameter.
    For example:

    dotCover.exe cover /TargetExecutable="C:\Program Files\dotnet\dotnet.exe" /TargetArguments="test -s C:\MyProject\mySettings.runsettings C:\MyProject\MyTests.csproj" /Output=snapshot.dcvr /UseApi


dotCover on TeamCity:

  • You have a TeamCity server with installed dotCover 2018.1.1 or later.
  • You have a .NET Core unit test project.
  • You want to perform coverage analysis of unit tests via dotCover.


To perform coverage analysis:

  1. Create (or modify an existing) a .runsettings file for the project, e.g. mySettings.runsettings.
  2. Modify the file based on the example below

    <?xml version="1.0" encoding="utf-8"?>  
    <RunSettings>
     <RunConfiguration>
       <DisableParallelization>True</DisableParallelization>
     </RunConfiguration>
     <InProcDataCollectionRunSettings>
       <InProcDataCollectors>
         <InProcDataCollector friendlyName="JetBrainsProfiler" uri="InProcDataCollector://JetBrains/JetBrainsProfiler/1.0" assemblyQualifiedName="<AQN>" codebase="PATH_TO_InProcDataCollector">
           <Configuration />
         </InProcDataCollector>
       </InProcDataCollectors>
     </InProcDataCollectionRunSettings>
    </RunSettings>

    Here
    • <AQN>: an assembly qualified name that depends on a dotCover version. For dotCover 2018.1.1, it is: JetBrains.Common.UnitTesting.InProcDataCollector.GrouplessCoverageInProcDataCollector, JetBrains.Common.UnitTesting.InProcDataCollector, Version=112.0.0.0, Culture=neutral, PublicKeyToken=1010a0d8d6380325
  3. On TeamCity server add “File content replacer” to Build Features to change PATH_TO_InProcDataCollector to %teamcity.tool.JetBrains.dotCover.CommandLineTools.DEFAULT%/JetBrains.Common.UnitTesting.InProcDataCollector.dll in mySettings.runsettings file:

    2018-05-28_1630.png

  4. Run coverage analysis in “.NET CLI(dotnet)” build step with “test” command type. Expand Advanced options, set a path to mySettings.runsettings and add /UseApi to the Additional arguments:

    2018-05-28_1844.png

    2018-05-28_1846.png


Please sign in to leave a comment.

Have more questions?

Submit a request