Vstest: Does .Net core 2.1 supports code coverage so can we skip coverlet?

Created on 22 Aug 2018  路  9Comments  路  Source: microsoft/vstest

I have searched all over internet and just getting information about previous .net core 2.0 that does not support code coverage. So, I am using coverlet for it but will update in future to .Net core 2.1. Will this new will support code coverage so that i can avoid using coverlet which I am using for my msbuild.

question

Most helpful comment

@singhsarab Is there somewhere a page how it is configured? The only thing I found is https://docs.microsoft.com/en-US/dotnet/core/tools/dotnet-test?tabs=netcore21 which is not really telling me anything.

Running e.g. dotnet test src\MyProject\MyProject.csproj "--logger:trx;LogFileName=MyProject.trx" --results-directory:..\..\src\TestResults\ --collect:"Code Coverage" generates a trx file but puts the output file into a folder named like a GUID. Is there an option to avoid this and put it to a defined file name and folder?

Plus: Is there an option to configure the output type (e.g. opencover or so) because I want to skip coverlet and that stuff as well as @ankitaLath?

I'm running my projects on .NetCore 2.2. by the way.

All 9 comments

@ankitaLath The support for dotnet test --collect:"Code Coverage" is available in .Net core 2.1, but currently is supported only on Windows.

Support for other OS and embedded pdbs is being tracked currently via https://github.com/Microsoft/vstest/issues/981

@singhsarab : Thanks for your reply. But can you please elaborate and tell me in respect to Visual Studio Team Services. I have an agent running in windows virtual machine(Azure VM) and that agent is integrated to VSTS and my .net core 2.1 C# build is running in VSTS. Currently I have referenced to coverlet nuget package in my project and getting the code coverage. Can you tell me what support to windows will be playing significant role in this. I am totally confused with your reply. As I am new to this VSTS(Visual Studio team service).

@ankitaLath
When you say .net core 2.1 C# build, I guessing you are talking about dotnet task in your build pipeline.
If above is true, it should work for you, since you are running on Windows VM.
Just make sure the version of dotnet >=2.1.400 (check the logs for that)

Regarding the support, agent configured for Mac or Linux will not be able to give you the coverage you need because dotnet test does not support code coverage on non-windows OS.

Ohh nice. Very nice explanation. Thanks @singhsarab.

@singhsarab Is there somewhere a page how it is configured? The only thing I found is https://docs.microsoft.com/en-US/dotnet/core/tools/dotnet-test?tabs=netcore21 which is not really telling me anything.

Running e.g. dotnet test src\MyProject\MyProject.csproj "--logger:trx;LogFileName=MyProject.trx" --results-directory:..\..\src\TestResults\ --collect:"Code Coverage" generates a trx file but puts the output file into a folder named like a GUID. Is there an option to avoid this and put it to a defined file name and folder?

Plus: Is there an option to configure the output type (e.g. opencover or so) because I want to skip coverlet and that stuff as well as @ankitaLath?

I'm running my projects on .NetCore 2.2. by the way.

Okay, I found out that currently only the .coverage file format is available as output which is only readable in VS Enterprise (see https://github.com/Microsoft/vstest/issues/1939). So, forget about the second question.

@SeppPenner We are integrating with coverlet and those options, hopefully you'd have soon.

Regarding the file name and folder, there is already an issue filed, you can up vote it. We are currently prioritizing other important issues based on feedback and we might not be able to take this one up as of now.
PS: That said, we would really like if you could contribute. Feel free to ping us if you need help.

@singhsarab I will see what I can do, but I'm busy at the moment with e.g. the German version of the Arduino reference and some other smaller projects. I will keep that in mind and hopefully come back later to help.

Okay, I found out that currently only the .coverage file format is available as output which is only readable in VS Enterprise (see #1939). So, forget about the second question.

Just in response to this, you can convert that .coverage file using the VSTS console.

$codeCoverageExe = "C:\Program Files (x86)\Microsoft Visual Studio\2017\TestAgent\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"

or

        $codeCoverageExe = "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Team Tools\Dynamic Code Coverage Tools\CodeCoverage.exe"

then

& $codeCoverageExe analyze /output:name.coveragexml $TestCoverageFile

this creates an XML file with the code coverage details from the .coverage file.

Was this page helpful?
0 / 5 - 0 ratings