Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code coverage on .NET Core #579

Closed
twsouthwick opened this issue Mar 8, 2017 · 62 comments
Closed

Code coverage on .NET Core #579

twsouthwick opened this issue Mar 8, 2017 · 62 comments

Comments

@twsouthwick
Copy link
Member

Description

Code coverage does not work in .NET Core

Steps to reproduce

Run vstest.console.exe /enablecodecoverage /framework:netcoreapp

Expected behavior

Runs the tests with code coverage enabled on .NET Core

Actual behavior

Error: Invalid .Net Framework version:netcoreapp11. Supported .Net Framework versions are Framework35, Framework40 and Framework45.

Environment

VS 2017 RTM
Windows 10 14393.693

@smadala
Copy link
Contributor

smadala commented Mar 8, 2017

Code coverage support not available in 15.0.0. Doc.

Please use /Framework:FrameworkCore10 for .Net core apps.

@smadala
Copy link
Contributor

smadala commented Mar 8, 2017

Error message should display as follows:
Error: Invalid .Net Framework version:netcoreapp11. Supported .Net Framework versions are Framework35, Framework40, Framework45 and FrameworkCore10.

@twsouthwick
Copy link
Member Author

twsouthwick commented Mar 16, 2017

What is the timeline to support .NET Core? Is this different on the console vs in Visual Studio?

@codito
Copy link
Contributor

codito commented Mar 17, 2017

@twsouthwick this will likely come in the next release (15.1 or 15.2 preview). We're still working out the details. Current thought process:

  • In console, code coverage will show up as a data collector (spec is here). User may install the code coverage nuget package, and use it like dotnet test --collect:coverage
  • In VS, it will show up as the existing Analyze Code Coverage in test explorer

We're first enabling the infrastructure (data collectors), this will allow the community to author code coverage extensions for dotnet test. VS code coverage support will use the same infra.

@robalexclark
Copy link

robalexclark commented Mar 30, 2017

I was struggling with this, but found Microsoft.CodeCoverage started working when I added <debugtype>Full/> to the project containing the assembly to have coverage:

I'm using Microsoft.CodeCoverage 1.0.2, xunit 2.2.0, Ms.Test.sdk 15.0. The project under test is .net framework 4.5.1 and uses nuget packages for .net core 1.1.1 throughout

Can someone else please check and confirm?

  <PropertyGroup>
    <TargetFramework>net452</TargetFramework>
    <RuntimeIdentifier>win7-x86</RuntimeIdentifier>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <AssemblyName>ExtranetManager</AssemblyName>
    <OutputType>Exe</OutputType>
    <DebugType>Full</DebugType>
    <PackageId>ExtranetManager</PackageId>
  </PropertyGroup>

@twsouthwick
Copy link
Member Author

@robalexclark your test is running on .NET Framework which is supported at the moment. The debugtype had to be changed because by default it builds with the new portable format, which is currently unsupported with vstest. If you switched your test to run as a .netcoreapp you won't see any coverage results.

uses nuget packages for .net core 1.1.1 throughout

This is probably not what you think it means. The nuget packages may support .NET Core 1.1.1, but are either targeting .NET Standard or have a .NET Framework version. These are then being selected when running on .NET Framework. The goal of .NET Standard is to allow the same binary to run on multiple runtimes (.NET Core and .NET Framework are two distinct runtimes).

If the project is one you can share, we can verify if this is the case based on the project files and packages.

@robalexclark
Copy link

Apologies yes you are right - I am running on .net 4.5.1 as runtime.

@twsouthwick
Copy link
Member Author

Easy mistake to make in some projects!

@pvlakshm pvlakshm mentioned this issue Apr 4, 2017
17 tasks
@baor
Copy link

baor commented Apr 10, 2017

Hi all!
Do you have any plans about implementation code coverage for dotNetCore for Linux?

If you have any not very complex PR or subtasks, I am ready to help.

@nperno
Copy link

nperno commented May 2, 2017

@codito I would like to try out the "dotnet test --collect:coverage" for my dotnet core VSTS builds. Do you have any insight/guidance as to when that will be available and we will need to do to get it working?

Thanks for your help!

@markvincze
Copy link

Hi all,

Is there any update on whether there will be .NET Core code coverage support for Linux too?

Thanks,
Mark

@HaroonSaid
Copy link

Any update - VS 2017 is expensive product one of key features is code coverage

@raffaeu
Copy link

raffaeu commented May 5, 2017

Guys just yesterday I found a new Nuget Package:
Microsoft.CodeCoverage version 1.0.3

I updated the package into my XUnit test project and run Tests + Code Coverage in VS 2017 Ultimate.
The tests are executed but the Code Coverage is not even triggered:

image

So, what's going on? Any official Docs yet?

@raffaeu
Copy link

raffaeu commented May 5, 2017

Also if I pass dotnet test --collect:coverage

This is what we get NOT IMPLEMENTED

MSBUILD : error MSB1001: Unknown switch.
Switch: --collect:coverage
For switch syntax, type "MSBuild /help"
Process completed with exit code 1.

@codito
Copy link
Contributor

codito commented May 5, 2017

This feature hasn't shipped yet. We're pretty close though, will provide an update soon :)

@codito
Copy link
Contributor

codito commented May 15, 2017

In 15.3 Preview 1, code coverage for .NET core is available in VS. Instructions are here: https://github.com/Microsoft/vstest-docs/blob/master/docs/analyze.md#coverage. Please try it out.

We're working on bringing coverage to dotnet test command line.

Sharing an alternate command line in case folks want to try it in CI. This will generate a .coverage file that can be published as reports.

> & "C:\Program Files (x86)\Microsoft Visual Studio\Preview\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" /framework:".NETCoreApp,Version=v1.1" /collect:"Code Coverage" "G:\tmp\trial\bin\Debug\netcoreapp1.1\trial.dll

Microsoft (R) Test Execution Command Line Tool Version 15.3.0-preview-20170427-09
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
[xUnit.net 00:00:00.6614583]   Discovering: trial
[xUnit.net 00:00:00.7762253]   Discovered:  trial
[xUnit.net 00:00:00.8162957]   Starting:    trial
[xUnit.net 00:00:00.9366491]   Finished:    trial

Attachments:
  G:\tmp\trial\TestResults\da20ba2e-2984-4d74-88d4-faf2bf018af0\armahapa_ARMAHAPA-SRV 2017-05-15 18_00_03.coverage

Total tests: 2. Passed: 2. Failed: 0. Skipped: 0.
Test Run Successful.
Test execution time: 2.1226 Seconds

@raffaeu
Copy link

raffaeu commented May 15, 2017

@codito we just tried with these versions:

  • Visual Studio 2017 15.2
  • xunit 2.2.0
  • Microsoft.NET.Test.Sdk" Version="15.3.0-preview-20170502-03"

Tests run and they are green but Code Coverage is not triggered.
Is it working only with MsTest? I hope we don't have to re-write all our tests 😢

@Mardoxx
Copy link

Mardoxx commented Aug 14, 2017

Still doesn't work in VS2017 15.3 (incl preview 7) on framework projects. My coverage only shows for my test library, coverage for the tested library is not shown. I guess it didn't ship? Live unit testing works however!

Works with following workaround https://github.com/Microsoft/vstest-docs/blob/master/docs/analyze.md#working-with-code-coverage

@harshjain2
Copy link
Contributor

@mstephens-adig VS 2017 15.3 is released now.
https://blogs.msdn.microsoft.com/visualstudio/2017/08/14/visual-studio-2017-version-15-3-released/
Upgrading to latest released version in VSTS should solve your problem.

@harshjain2
Copy link
Contributor

@Mardoxx Thanks for trying it out. This workaround is required for code coverage to work on .NET Core

@harshjain2
Copy link
Contributor

Please try code coverage and let us know if there is any feedback/issues.
I am closing this issue for now.

@cdie
Copy link

cdie commented Aug 21, 2017

@harshjain2 Is the nuget package a temporary workaround or a permanent one ? I mean I don't want to spent a lot of time adding it now to remove it in two months...

@cdie
Copy link

cdie commented Aug 22, 2017

It seems it's not working with .NET Core 2.0 ?
Or maybe it's with xunit 2.2.0 ?

@IvanAlekseev
Copy link

Coverage is still not working in VSTS, at least I can get the test results
microsoft/azure-pipelines-tasks#5066

@Mardoxx
Copy link

Mardoxx commented Aug 23, 2017

I would imagine this is because your agent is not up to date. Check what version of VS2017 your agent is using. Any >15.3 should work.

@IvanAlekseev
Copy link

@Mardoxx It is Hosted VS 2017, they updated to 15.3 recently

@Mardoxx
Copy link

Mardoxx commented Aug 23, 2017

Ah! Now I look, mine don't have coverage either!

@harshjain2
Copy link
Contributor

harshjain2 commented Aug 24, 2017

@harshjain2 Is the nuget package a temporary workaround or a permanent one ? I mean I don't want to spent a lot of time adding it now to remove it in two months...
@cdie We are tracking the issue to remove need to manually add nuget package here.
#852.
We will prioritize it soon.

@a0z0ra
Copy link

a0z0ra commented Aug 24, 2017

Hi, we followed all above, and still no luck. Found different paths from log:

2017-08-24T22:58:11.1157918Z Attachments:
2017-08-24T22:58:11.1157918Z d:\a\1\s\TestResults\672524f6-3c0c-4dc4-86c9-4b58f01c9577\buildguest_FACTORYVM-AZ220 2017-08-24 22_58_06.coverage
2017-08-24T22:58:11.1157918Z
2017-08-24T22:58:11.1157918Z Total tests: 1. Passed: 1. Failed: 0. Skipped: 0.
2017-08-24T22:58:11.1157918Z Test Run Successful.
2017-08-24T22:58:11.1167892Z Test execution time: 4.6567 Seconds
2017-08-24T22:58:11.1508492Z Results File: d:\a\1\s\TestResults\buildguest_FACTORYVM-AZ220_2017-08-24_22_58_11.trx
2017-08-24T22:58:13.3673473Z ##[section]Async Command Start: Telemetry
2017-08-24T22:58:13.3673473Z ##[section]Async Command End: Telemetry
2017-08-24T22:58:13.3673473Z ##[section]Async Command Start: Telemetry
2017-08-24T22:58:13.3673473Z ##[section]Async Command End: Telemetry
2017-08-24T22:58:13.3673473Z ##[section]Async Command Start: Telemetry
2017-08-24T22:58:13.3673473Z ##[section]Async Command End: Telemetry
2017-08-24T22:58:13.3673473Z ##[section]Async Command Start: Telemetry
2017-08-24T22:58:13.3673473Z ##[section]Async Command End: Telemetry
2017-08-24T22:58:13.3673473Z ##[section]Async Command Start: Publish test results
2017-08-24T22:58:13.8241527Z Publishing test results to test run '59'
2017-08-24T22:58:13.8241527Z Test results remaining: 1. Test run id: 59
2017-08-24T22:58:14.1399971Z ##[warning]Skipping attachment as it exceeded the maximum allowed size or not available on disk: d:\a\1\s\TestResults\buildguest_FACTORYVM-AZ220_2017-08-24_22_58_11\In\FACTORYVM-AZ220\buildguest_FACTORYVM-AZ220 2017-08-24 22_58_06.coverage

Could this be the case why codecoverage not published?

Also, once it's published, should it be visible under Code Coverage?

@harshjain2
Copy link
Contributor

CC @nigurr for vstest-task

@nigurr
Copy link

nigurr commented Aug 28, 2017

Hi,

We are fixing this issue as part of this https://github.com/Microsoft/vsts-agent/pull/1149/files
Will update the thread once we release the fix.

Sorry for the trouble.

@xperiandri
Copy link

@Oceanswave
Copy link

Getting similar results as folks above

is referenced in my test project.

dotnet test --collect:coverage
Microsoft (R) Test Execution Command Line Tool Version 15.3.0-preview-20170628-02
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
dotnet exec needs a managed .dll or .exe extension. The application specified was 'C:\Program'

Object reference not set to an instance of an object.
Object reference not set to an instance of an object.

@davidreher
Copy link

even if I use vstest.console.exe like described in https://github.com/Microsoft/vstest-docs/blob/master/docs/analyze.md#coverage like this:

vstest.console.exe --collect:"Code Coverage" --framework:".NETCoreApp,Version=v2.0" bin\Debug\netcoreapp2.0\some.tests.dll

I am getting:

Microsoft (R) Test Execution Command Line Tool Version 15.0.26929.2
Copyright (c) Microsoft Corporation.  All rights reserved.

Error: The test source file "--collect:Code Coverage" provided was not found.
Error: The test source file "--framework:.NETCoreApp,Version=v2.0" provided was not found.

I am running VS2017 Enterprise V15.4.1

@sbaid
Copy link
Contributor

sbaid commented Oct 25, 2017

pl use the vstest.console.exe in testplatform folder for .NET core

C:\Program Files (x86)>dir vstest.console.exe /s
 Volume in drive C is OSDisk
 Volume Serial Number is 4445-DB68

 Directory of C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow

10/10/2017  09:42 AM           137,824 vstest.console.exe
               1 File(s)        137,824 bytes

 Directory of C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\**TestPlatform**

09/06/2017  09:43 AM           133,240 vstest.console.exe
               1 File(s)        133,240 bytes

@davidreher
Copy link

@sbaid: Thank you so much, this works now :)

@davidreher
Copy link

Is there a way to pass the --collect:"Code Coverage" switch to dotnet vstest instead of using vstest.console.exe?

@mundhras
Copy link

mundhras commented Mar 5, 2018

I get the below error. Has any one see/resolved this.

Test run will use DLL(s) built for framework NETCoreApp,Version=v2.0 and platform X86. Following DLL(s) do not match framework/platform settings.
.Test.dll is built for Framework 2.0 and Platform X86.

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" F:\Vsts\agent-1_work\14\a\Release\Deploy\Publications<folder><asembly>.Test.dll /EnableCodeCoverage /logger:trx "/TestAdapterPath:"F:\Vsts\agent-1_work\14\a"" /Framework:NETCoreApp,Version=v2.0 /logger:console;verbosity=normal

@BlitzkriegSoftware
Copy link

BlitzkriegSoftware commented Apr 17, 2018

This is still an issue for XUnit on .NET Core 2.0 projects in the latest VS 2017. Why is this closed?

@Oceanswave
Copy link

Since Microsoft is unwilling or unable to provide a solution at this time, check out Coverlet:

https://github.com/tonerdo/coverlet

@IvanAlekseev
Copy link

Thats the latest update from Microsoft I believe - https://github.com/Microsoft/vstest-docs/blob/master/RFCs/0021-CodeCoverageForNetCore.md

@swati-jain13
Copy link

Is there a solution available now for dotnet test --collect:Code Coverage for linux containers?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests