Instrumenting non used assemblies produces non existing branches (whith hits =0) in branch coverage. Lowering coverage when using /p:MergeWith
See original GitHub issue@tonerdo When calculating the coverage from an assembly that’s referenced in another test project, I get some differences on branch coverage than when i run the tests for the actual test project that is ment to test that assembly
+----------------------+--------+--------+--------+
| Module | Line | Branch | Method |
+----------------------+--------+--------+--------+
| ProjectName.Api | 100% | 100% | 100% |
+----------------------+--------+--------+--------+
| ProjectName.Application | 100% | 60% | 100% |
+----------------------+--------+--------+--------+
| ProjectName.Data | 100% | 62.5% | 100% |
+----------------------+--------+--------+--------+
But separately:
ProjectName.Data:
+---------------+--------+--------+--------+
| Module | Line | Branch | Method |
+---------------+--------+--------+--------+
| ProjectName.Data | 100% | 100% | 100% |
+---------------+--------+--------+--------+
ProjectName.Application:
+----------------------+--------+--------+--------+
| Module | Line | Branch | Method |
+----------------------+--------+--------+--------+
| ProjectName.Application | 100% | 75% | 100% |
+----------------------+--------+--------+--------+
|ProjectName.Data | 0% | 0% | 0% |
+----------------------+--------+--------+--------+
ProjectName.Api:
+----------------------+--------+--------+--------+
| Module | Line | Branch | Method |
+----------------------+--------+--------+--------+
| ProjectName.Api | 100% | 100% | 100% |
+----------------------+--------+--------+--------+
| ProjectNameApplication | 0% | 0% | 0% |
+----------------------+--------+--------+--------+
| ProjectName.Data | 0% | 0% | 0% |
+----------------------+--------+--------+--------+
So my idea was to get:
+----------------------+--------+--------+--------+
| Module | Line | Branch | Method |
+----------------------+--------+--------+--------+
| ProjectName.Application | 100% | 75% | 100% |
+---------------+--------+--------+--------+
| ProjectName.Data | 100% | 100% | 100% |
+---------------+--------+--------+--------+
| ProjectName.Api | 100% | 100% | 100% |
+----------------------+--------+--------+--------+
Just noticed ProjectName.Application
detects some branches of the ProjectName.Data
that ProjectName.Data
does not detect when running the coverage for itself alone.
Is this normal/possible?
"ProjectName.Repositories.KeyRepository/<AddAsync>d__4": {
"System.Void ProjectName.Repositories.KeyRepository/<AddAsync>d__4::MoveNext()": {
"Lines": {
"34": 4,
"35": 4,
"36": 1,
"37": 1,
"40": 3,
"41": 3,
"42": 3
},
"Branches": [
{
"Line": 41,
"Offset": 98,
"EndOffset": 100,
"Path": 0,
"Ordinal": 2,
"Hits": 0
},
{
"Line": 41,
"Offset": 98,
"EndOffset": 165,
"Path": 1,
"Ordinal": 3,
"Hits": 0
}
]
"ProjectName.Data.Repositories.KeyRepository/<AddAsync>d__4": {
"System.Void ProjectName.Data.Repositories.KeyRepository/<AddAsync>d__4::MoveNext()": {
"Lines": {
"34": 4,
"35": 4,
"36": 1,
"37": 1,
"40": 3,
"41": 3,
"42": 3
},
"Branches": [
{
"Line": 41,
"Offset": 98,
"EndOffset": 165,
"Path": 1,
"Ordinal": 3,
"Hits": 1
}
]
Issue Analytics
- State:
- Created 5 years ago
- Comments:22 (15 by maintainers)
Top Results From Across the Web
Branch coverage never reaches 100%
The test report never reaches 100% of branch coverage because of the statement below. Why there are 6 branches to cover on a...
Read more >Apply assembly-wide `ExcludeFromCodeCoverageAttribute`
When using .NET's native code coverage collection mechanism - dotnet test with --collect "Code Coverage;Format=Cobertura", the Xunit assemblies also count ...
Read more >What Is Branch Coverage and What Does It Really Tell You?
We'll start answering the “what” question by providing a quick definition of branch coverage. We'll then follow that with an explanation of ...
Read more >QUESTION 7 Branch coverage (running a series of tests ...
The answer is FALSE. Branch coverage is not sufficient to detect all the faults in the code. Branch coverage i… View the full...
Read more >coverlet.msbuild 2.1.0
Coverlet is a cross platform code coverage library for .NET Core, with support for line, branch and method coverage.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@tonerdo i updated my pr to add this as an option so default behaviour remains the same and fixes the issues for those who need to exclude non used files from coverage (#225)
I got an error when doing some http post call for a vs 2015 test on app veyor. Probably if you re run it, it will work. Would you consider this for merging with this as an option? 😃
Hi @pape77 it works like in the past nothing changed on that side we’re waiting to use new extension point from vstest plat https://github.com/coverlet-coverage/coverlet/issues/1015#issuecomment-746174446
https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/DriversFeatures.md https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/MSBuildIntegration.md#merging-results https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/GlobalTool.md#coverlet-as-a-global-tool And your trick is documented for collectors https://github.com/coverlet-coverage/coverlet/blob/master/Documentation/VSTestIntegration.md#coverlet-options-supported-by-vstest-integration (thanks)