> dotnet dotсover test

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?

This entry was posted in How-To's and tagged , , , , . Bookmark the permalink.

28 Responses to > dotnet dotсover test

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

  2. anuraj says:

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

  3. Adam says:

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

  4. Josh says:

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

  5. Bernhard says:

    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)?

  6. Richard says:

    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:

      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:

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

        • Alexey Totin says:

          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.

  7. Riyas says:

    Hi,

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

  8. Chris says:

    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

    • Alexey Totin says:

      Hi Chris,
      we don’t change the functionality of ‘dotnet test’ in any way. So, yes, it must work on a solution level.
      UPD: sorry, it seems, I was too quick to answer. We’ve just checked this, and it appears to be a bug there. I’ve made a request, feel free to upvote.
      https://youtrack.jetbrains.com/issue/DCVR-9681
      And sorry for the inconvenience!

Leave a Reply to Richard Cancel reply

Your email address will not be published. Required fields are marked *