Coverlet: Include doesn't seem to work

Created on 29 Aug 2018  路  11Comments  路  Source: coverlet-coverage/coverlet

Using the NuGet integration (haven't tried the global tool), I want to be able to include only the coverage from the project I'm unit testing.

I have multiple projects and multiple test projects:

  • StackState.Core
  • StackState.Core.UnitTests
  • StackState.CLI
  • StackState.Monitor
  • StackState.Monitor.UnitTests

When I generate coverage for the "StackState.Monitor.UnitTests" project, without specifying any include or exclude filters, the result is this:

+---------------------------+--------+--------+--------+ | Module | Line | Branch | Method | +---------------------------+--------+--------+--------+ | StackState.Core | 0,4% | 0% | 0,7% | +---------------------------+--------+--------+--------+ | StackState.Core.UnitTests | 4,4% | 0% | 6,8% | +---------------------------+--------+--------+--------+ | StackState.Monitor | 37,6% | 21,7% | 56,5% | +---------------------------+--------+--------+--------+

When I add "/p:Exclude="[StackState.Core]"", the result is:

+--------------------+--------+--------+--------+ | Module | Line | Branch | Method | +--------------------+--------+--------+--------+ | StackState.Monitor | 37,6% | 21,7% | 56,5% | +--------------------+--------+--------+--------+

The above is actually what I want, but I want to get this result by INcluding the one project that 1 want coverage for and not EXcluding everything else. Besides that it's cumbersome, it's also currently not possible to do from a PowerShell window: https://github.com/tonerdo/coverlet/issues/182. Anyway, changing the parameter to "/p:Include="[StackState.Monitor]"" results again in:

+---------------------------+--------+--------+--------+ | Module | Line | Branch | Method | +---------------------------+--------+--------+--------+ | StackState.Core | 0,4% | 0% | 0,7% | +---------------------------+--------+--------+--------+ | StackState.Core.UnitTests | 4,4% | 0% | 6,8% | +---------------------------+--------+--------+--------+ | StackState.Monitor | 37,6% | 21,7% | 56,5% | +---------------------------+--------+--------+--------+

Either I'm doing something wrong, or the include setting doesn't seem to work.

So why is this an issue at all? I'm trying to get Coverage Gutters working together with Coverlet, but when Code Gutters finds multiple coverage files with overlapping values it seems to pick the last one and not combine the data. As combining coverage results isn't possible yet with Coverlet as well, this seems to be my only way out.

bug

All 11 comments

Hi @rvanmaanen, thanks for reporting this. I'm actually in the process of revamping the include/exclude capabilities of Coverlet. Will have some new updates within the week

@rvanmaanen I tested this and Include seems to work just fine. Do you think you can put together a simple repro solution that I can clone? Also, while I know it's cumbersome I've provided a solution to the Powershell issue here https://github.com/tonerdo/coverlet/issues/182#issuecomment-417868403

Hi, sorry for the delay! Here is a repo containing an example: https://github.com/rvanmaanen/CoverletIncludeIssues

Is there a reason exclude takes precedence over include? Something like the following could be useful: exclude everything and then include what you want?

dotnet test Demo2.Test /p:CollectCoverage=true /p:Include="[Demo2]*" /p:Exclude="[*]*"

@rvanmaanen no particular reason, it's just by design. I took into consideration that everything is included by default and most users would typically want to start out in that default state

Hi are there any updates on the /p:Include= functionality? It doesn't work for me either and I'm using terminal on a mac.

I'm having the same problem: /p:Include is not working.

Same problem here. @tonerdo Might it be that the msbuild targets do not include the Include property? My understanding of target files is not great but it seems that it does not pass along the property.

@MortenChristiansen thanks for pointing that out!

this bug is solved I did a test with last version 2.7.0 and this is my result of repro.

C:\git\coverletissue\CoverletIncludeIssues (master -> origin)
位 dotnet test Demo2.Test /p:CollectCoverage=true /p:Include="[Demo2]*
Test run for C:\git\coverletissue\CoverletIncludeIssues\Demo2.Test\bin\Debug\netcoreapp2.1\Demo2.Test.dll(.NETCoreApp,Version=v2.1)
Microsoft (R) Test Execution Command Line Tool Version 16.3.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...

A total of 1 test files matched the specified pattern.

Test Run Successful.
Total tests: 1
     Passed: 1
 Total time: 1,7034 Seconds

Calculating coverage result...
  Generating report 'C:\git\coverletissue\CoverletIncludeIssues\Demo2.Test\coverage.json'

+--------+------+--------+--------+
| Module | Line | Branch | Method |
+--------+------+--------+--------+
| Demo2  | 100% | 100%   | 100%   |
+--------+------+--------+--------+

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 100% | 100%   | 100%   |
+---------+------+--------+--------+
| Average | 100% | 100%   | 100%   |
+---------+------+--------+--------+

I'm going to close...feel free to reopen if needed.

Was this page helpful?
0 / 5 - 0 ratings