> dotnet dotсover test

Alexey Totin

Important: This post is outdated. Please use the instructions from the dotCover documentation.

If you’ve got the idea of this post just by reading the title, you may skip the next paragraph and go right to the procedure.

We’re going to talk about the dotCover.exe console runner and a new way to run coverage analysis of unit tests. While the dotnet tool simplified running tests a long time ago (dotnet test in the working directory is enough), dotCover.exe still required you to specify a lot of arguments in order to run tests, like an absolute path to the dotnet.exe, path to a .dll with tests, and others. Too much to type, and moreover, there’s no guarantee the paths won’t change at some point. In 2018.2, we came up with a solution: the “dotnet” way to run tests under coverage analysis. All you need is to insert the dotсover argument to the original string:
dotnet dotсover test

So, this is how you can make it work (steps 1-4 are made only once per project):

  1. Go to nuget.org and find the dotCover.CommandLineTools package.
  2. Do NOT reference this package in your unit tests project. Instead, open its .csproj file and add the following line that contains the package name and the current version (2018.2 EAP03 or later):
    <DotNetCliToolReference Include="JetBrains.dotCover.CommandLineTools" Version="2018.2.0-eap03" />
  3. In the command line, go to the directory containing your unit tests project.
  4. Run dotnet restore
    This will download dotCover command line tools to your computer.
  5. Run tests with coverage analysis:
    dotnet dotсover test

Important notes:

  1. The suggested way of using the console runner is NOT a replacement but an addition to the good old dotCover.exe. You can still use it to analyze coverage if you want to.
  2. If you want to specify any argument you’ve used previously with dotCover.exe, you can do this by simply adding the dc prefix to the argument name. E.g., to specify a report type, use --dcReportType instead of --ReportType:
    dotnet dotсover test --dcReportType=XML
  3. You don’t have to specify whether you want to cover (a coverage snapshot is saved) or analyze (a human-readable report is saved). This is one more improvement in this release that also applies to dotCover.exe. Now, the --ReportType / --dcReportType is the only argument you should use: if it is specified, you’ll get a report of a certain type; if not, a regular coverage snapshot will be saved.
  4. If you configured dotCover.exe via an XML file and want to continue using it, simply specify a path to the file
    dotnet dotсover test --dcXML="C:\config\config.xml"
    All parameters in the XML file that are not applicable to the new runner will be ignored.

One more important thing: the updated runner doesn’t require any additional workarounds for getting coverage of long-running tests (> 100 ms).

All in all, dotnet dotсover test is the fastest and easiest way to analyze tests coverage from the command line. It’s already available in ReSharper Ultimate 2018.2 EAP, so why not check it out right now?

Comments below can no longer be edited.

43 Responses to > dotnet dotсover test

  1. Dew Drop - August 1, 2018 (#2778) - Morning Dew says:

    August 1, 2018

    […] > dotnet dotCover test (Alexey Totin) […]

  2. anuraj says:

    August 2, 2018

    I am getting an error like this – No executable found matching command “dotnet-dotCover”

    • alexander.mikhailov says:

      August 2, 2018

      Hi anuraj,

      please double check that:
      1) You have added with version not less than 2018.2.0-eap03
      2) You have restored project
      3) You are running command from a directory where *proj file is located

      • anuraj says:

        August 3, 2018

        Thank you. It was due to the case sensitivity issue.

        • Alexey Totin says:

          August 3, 2018

          Thank you and sorry for the inconvenience!

      • Alexander Kurakin says:

        August 3, 2018

        The whole discussion and the solution are here https://twitter.com/dotCover/status/1025008542057725952

        • Oskar Mamrzynski says:

          October 11, 2018

          This still doesn’t work for me…
          Added this in the non-test csproj:

          Browsed to unit test directory. Ran “dotnet restore” and “dotnet dotcover test”.

          PS C:\Workspace\AML\src\WTW.AML.Host.Common.UnitTests> dotnet dotcover test
          dotnet : No executable found matching command “dotnet-dotcover”

          There is a dotnet-dotcover exe in the .nuget folder, so the restore was successful.

          • Oskar Mamrzynski says:

            October 11, 2018

            Never mind.. I misread the docs.. You’re supposed to add the reference to test .csproj not the .csproj of the product code.

  3. Adam says:

    August 15, 2018

    I worth to also mansion is working only through cmd not PowerShell (at least on my PC)

    • Alexey Totin says:

      August 20, 2018

      Hi Adam,
      actually, it should work through Powershell as well. Could you please share the output?

  4. Josh says:

    August 29, 2018

    Will this work on linux with dotnet core? Or is this still Windows only?

    • Alexey Totin says:

      August 29, 2018

      Hi Josh, currently it’s Windows only.

      • Cedric says:

        January 3, 2019

        When do you plan to support native dotnet on linux too?

        • Alexey Totin says:

          January 4, 2019

          Hi Cedric,
          Yes, it is planned for the next releases.

          • Cedric says:

            January 4, 2019

            Yes!

  5. Bernhard says:

    October 29, 2018

    Having multiple test projects, we need to merge the output from dotnet-dotcover into 1 file. Is this possible with dotnet-dotcover or do we have to use dotcover directly (with merge command)?

    • Alexey Totin says:

      November 6, 2018

      Hi Bernhard,
      You should use dotcover.exe directly to merge snapshots.

  6. Richard says:

    January 16, 2019

    Hello!
    May I asked when will be released next release with dot cover for Linux/Ubuntu? Some more specific horizon – a bit?
    Thanks,
    Richard.

    • Alexey Totin says:

      January 16, 2019

      Hi Richard,
      there will be no standalone dotCover for Linux/macOS. Only as a part of Rider. Currently, this is planned for 2019.1 but the date can move.

      • Daniel says:

        February 7, 2019

        We need dotCover for our docker CI. Why won’t there be a standalone version?

        • Alexey Totin says:

          February 7, 2019

          Hi Daniel,
          sorry for the confusion. By ‘standalone dotCover’ I meant a desktop application with GUI (the one we have on Windows). So, there will be no standalone dotCover on Linux/mac. But, there will be a command line tool, a counterpart of dotcover.exe. So, stay tuned.

          • Daniel says:

            February 8, 2019

            Okay, this is great news!

          • Petr Mašlaň says:

            April 15, 2019

            Hi Alexey,
            is there any progress? I downloaded last EAP and it looks it is still only for Windows.

            • Alexey Totin says:

              April 15, 2019

              Hi Petr,
              unfortunately, command-line tools will not be a part of 2019.1. Probably, 2019.2. Sorry for the inconvenience.

  7. Riyas says:

    February 27, 2019

    Hi,

    Can we use this for .net framework 4.7 unit test project? I have tried and I have received version not supported error

    • Alexey Totin says:

      February 28, 2019

      Hi,
      the .NET Framework 4.7 is supported. Could you please provide the full error message?

  8. Chris says:

    April 16, 2019

    Obviously I’d like to run at the solution level, to run all tests in the solutions.
    How can I make dotnet dotCover work in the solution directory?
    Thanks
    Chris

  9. Meghraj Mitkari says:

    June 12, 2019

    JustMock =2017 R3
    Reshraper=2019
    Issue:
    When I am generating code coverage report, it not generating.
    It’s show’s status as “Coverage analysis is in progress…”

  10. Lee says:

    September 5, 2019

    Hi.
    I tried to call ‘dotnet restore’.But command respons is always error message.
    Could you please tell me what is wrong .
    “`
    dotnet restore
    C:\Program Files\dotnet\sdk\2.1.507\NuGet.targets(114,5): error : Value cannot be null. [C:\Users\satom.INTERNAL\source\repos\SampleDotCoverConsoleApp\SampleDotCoverConsoleApp.sln]
    C:\Program Files\dotnet\sdk\2.1.507\NuGet.targets(114,5): error : Parameter name: key [C:\Users\satom.INTERNAL\source\repos\SampleDotCoverConsoleApp\SampleDotCoverConsoleApp.sln]
    “`
    ——- My Environment:
    OS: Windows10 pro 64bit 10.0.17134
    VS:
    Microsoft Visual Studio Professional 2017
    Version 15.9.12
    VisualStudio.15.Release/15.9.12+28307.665
    Microsoft .NET Framework
    Version 4.7.03056
    —— What did I do.
    1. Create .NetFramework Console Solution.
    2.Add .NetFrameWork test Project.
    3.Edit Test Project csproj file.
    add

    • Lee says:

      September 5, 2019

      csproj add
      “`

      “`

    • Lee says:

      September 5, 2019

      I add to csproj tag message. But tag message disappear in here.
      “`
      DotNetCliToolReference Include=”JetBrains.dotCover.CommandLineTools” Version=”2018.2.0″
      “`
      I write only contents of the tag.

      • Alexey Totin says:

        September 5, 2019

        Hi Lee,
        could you please try the newer version of the tool:
        https://www.jetbrains.com/help/dotcover/Running_Coverage_Analysis_from_the_Command_LIne.html#using-dotnet-exe-to-run-coverage-analysis-of-unit-tests

        and please check the syntax. Currently, it seems that you have an issue somewhere in the .csproj file as the message you receive is from dotnet and not from dotCover.

        • Lee says:

          September 9, 2019

          Thanks Alexey Totin.
          I create another project. And try to use DotNetCliToolReference.
          I find out DotNetCliToolReference and dotnet restore be error.
          I will question to MS community.

          • Alexey Totin says:

            September 10, 2019

            Hi Lee,
            could you please share the error you get from dotnet restore?

            • Lee says:

              September 11, 2019

              Hi Alexey Totin.

              I got this.
              “`
              dotnet restore
              C:\Program Files\dotnet\sdk\2.1.507\NuGet.targets(114,5): error : Value cannot be null. [C:\Users\satom.INTERNAL\source\repos\SampleDotCoverConsoleApp\SampleDotCoverConsoleApp.sln]
              C:\Program Files\dotnet\sdk\2.1.507\NuGet.targets(114,5): error : Parameter name: key [C:\Users\satom.INTERNAL\source\repos\SampleDotCoverConsoleApp\SampleDotCoverConsoleApp.sln]
              “`
              I wrote at the beginning.

              • Alexey Totin says:

                September 11, 2019

                Hi Lee,
                yes, looks like the error is on the dotnet side

  11. Lee says:

    September 11, 2019

    Hi Alexey Totin.

    I got this.
    “`
    dotnet restore
    C:\Program Files\dotnet\sdk\2.1.507\NuGet.targets(114,5): error : Value cannot be null. [C:\Users\satom.INTERNAL\source\repos\SampleDotCoverConsoleApp\SampleDotCoverConsoleApp.sln]
    C:\Program Files\dotnet\sdk\2.1.507\NuGet.targets(114,5): error : Parameter name: key [C:\Users\satom.INTERNAL\source\repos\SampleDotCoverConsoleApp\SampleDotCoverConsoleApp.sln]
    “`
    I wrote at the beginning.

  12. Ranjithkumar Rajendran says:

    September 27, 2019

    Hi,

    I have a solution with .net & .net core project. I need to get the code coverage by Sonarqube (Dotcover).
    Able to generate is separately but how to merge those two?

    Any suggesestion?

    Regards,
    Ranjithkumar.R

    • Alexey Totin says:

      September 30, 2019

      Hi Ranjithkumar,
      sorry, could you please clarify what you’re trying to achieve? Do you want to merge a coverage snapshot from Sonarqube with the one from dotCover? If yes, it’s not possible. What’s the reason for using both Sonarqube and dotCover?

Subscribe

Subscribe to .NET Tools updates