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):
- Go to nuget.org and find the dotCover.CommandLineTools package.
- 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" />
- In the command line, go to the directory containing your unit tests project.
- Run
dotnet restore
This will download dotCover command line tools to your computer. - Run tests with coverage analysis:
dotnet dotсover test
Important notes:
- 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.
- If you want to specify any argument you’ve used previously with
dotCover.exe
, you can do this by simply adding thedc
prefix to the argument name. E.g., to specify a report type, use--dcReportType
instead of--ReportType
:
dotnet dotсover test --dcReportType=XML
- You don’t have to specify whether you want to
cover
(a coverage snapshot is saved) oranalyze
(a human-readable report is saved). This is one more improvement in this release that also applies todotCover.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. - 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?
Pingback: Dew Drop - August 1, 2018 (#2778) - Morning Dew
I am getting an error like this – No executable found matching command “dotnet-dotCover”
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
Thank you. It was due to the case sensitivity issue.
Thank you and sorry for the inconvenience!
The whole discussion and the solution are here https://twitter.com/dotCover/status/1025008542057725952
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.
Never mind.. I misread the docs.. You’re supposed to add the reference to test .csproj not the .csproj of the product code.
I worth to also mansion is working only through cmd not PowerShell (at least on my PC)
Hi Adam,
actually, it should work through Powershell as well. Could you please share the output?
Will this work on linux with dotnet core? Or is this still Windows only?
Hi Josh, currently it’s Windows only.
When do you plan to support native dotnet on linux too?
Hi Cedric,
Yes, it is planned for the next releases.
Yes!
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)?
Hi Bernhard,
You should use dotcover.exe directly to merge snapshots.
Hello!
May I asked when will be released next release with dot cover for Linux/Ubuntu? Some more specific horizon – a bit?
Thanks,
Richard.
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.
We need dotCover for our docker CI. Why won’t there be a standalone version?
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.
Okay, this is great news!
Hi Alexey,
is there any progress? I downloaded last EAP and it looks it is still only for Windows.
Hi Petr,
unfortunately, command-line tools will not be a part of 2019.1. Probably, 2019.2. Sorry for the inconvenience.
Hi,
Can we use this for .net framework 4.7 unit test project? I have tried and I have received version not supported error
Hi,
the .NET Framework 4.7 is supported. Could you please provide the full error message?
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
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!
Hi Alexey,
Is there any update to this request?
We wanted to run code coverage for all the test projects in the solution and it doesn’t work in solution level.
If this is not yet fixed, any other way to achieve the goal or any work around ?
Hi Surjeet,
unfortunately, it appears that we could not make it for ‘dotnet’ as it is extensible only on per-project level (https://docs.microsoft.com/en-us/dotnet/core/tools/extensibility#per-project-based-extensibility).
But we’re working on a workaround – using a ‘dotcover cover-dotnet’ command on a solution level. It is already done and will become publicly available in 2019.2.3
https://www.jetbrains.com/help/dotcover/Running_Coverage_Analysis_from_the_Command_LIne.html#basic-scenario-for-net-core
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…”
Hi Meghraj,
could you please file an issue in our tracker with more details (type of the application, framework version, etc.)? https://youtrack.jetbrains.com/issues/DCVR
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
csproj add
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.
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.
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.
Hi Lee,
could you please share the error you get from dotnet restore?
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.
Hi Lee,
yes, looks like the error is on the dotnet side
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.
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
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?