You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+35-26
Original file line number
Diff line number
Diff line change
@@ -13,10 +13,10 @@ or download from [releases](https://github.com/FortuneN/FineCodeCoverage/release
13
13
14
14
For .Net
15
15
16
-
FCC supports the new [Microsoft.Testing.Platform](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-platform-intro).
16
+
FCC supports the new [Microsoft.Testing.Platform](https://learn.microsoft.com/en-us/dotnet/core/testing/unit-testing-platform-intro).
17
17
FCC does not support the associated testing platform server mode for when using microsoft as a coverage provider.
18
18
You can disable this feature - "Options / Environment / Preview Features / Use testing platform server mode"
19
-
but it is not necessary as FCC adds a global msbuild property, DisableTestingPlatformServerCapability true, that removes
19
+
but it is not necessary as FCC adds a global msbuild property, DisableTestingPlatformServerCapability true, that removes
20
20
the project capability. ([see Microsoft.Testing.Platform.MSBuild.targets](https://github.com/microsoft/testfx/blob/d141931b99fad0617d8435ce321fca0c45c9eb94/src/Platform/Microsoft.Testing.Platform.MSBuild/buildMultiTargeting/Microsoft.Testing.Platform.MSBuild.targets#L10)).
21
21
22
22
When not using Microsoft.TestingPlatform you have added test adapters through nuget packages. For instance, the NUnit Test Adapter extension is not sufficient.
@@ -111,7 +111,7 @@ The old coverage was based upon every test. Ms code coverage is coverage from th
111
111
112
112
Ms code coverage requires a [runsettings](https://docs.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2022) file that is configured appropriately for
113
113
code coverage. This requires that you have the ms code coverage package and have pointed to it with the TestAdaptersPaths element as well as specifying the ms data collector. [Exclusions and inclusions](https://docs.microsoft.com/en-us/visualstudio/test/customizing-code-coverage-analysis?view=vs-2022#include-or-exclude-assemblies-and-members)
114
-
are also specified in the runsettings. I don't think that the documentation is clear enough on how this works so you may want to look at [this issue](https://github.com/microsoft/vstest/issues/3462).
114
+
are also specified in the runsettings.
115
115
116
116
FCC does not require you to do this. If you do not provide a runsettings and RunMsCodeCoverage is Yes then FCC will generate one and write the necessary entry in the project file.
117
117
Note that having a test project file open in visual studio whilst running tests may result in a conflict warning when FCC removes the entry at the end of the test.
@@ -140,9 +140,12 @@ It is also possible to use your own runsettings file and have FCC add to it and
140
140
141
141
## Run settings defaults and merging
142
142
143
-
Ms code coverage does provide a default Configuration / CodeCoverage element if not provided. It will also add some default exclusions if not present or merge them in unless you add the attribute mergeDefaults='false'.
144
-
For instance it Attributes exclude ExcludeFromCodeCoverageAttribute.
145
-
If you are interested see ...\AppData\Local\FineCodeCoverage\msCodeCoverage_version\_\build\netstandard1.0\Microsoft.VisualStudio.TraceDataCollector.dll and the DynamicCoverageDataCollector.
143
+
Ms code coverage does provide a default Configuration / CodeCoverage element if not provided. It will also add some default exclusions for ModulePaths, Attributes, Sources, Functions, and PublicKeyTokens if not present in inclusions or exclusions unless you add the attribute mergeDefaults='false'.
144
+
For instance for Attributes it will exclude ExcludeFromCodeCoverageAttribute.
145
+
146
+
If you are interested in using DotPeek or Reflector against the Microsoft source code within
147
+
...\AppData\Local\FineCodeCoverage\msCodeCoverage_version\_\build\netstandard2.0\ there is the Microsoft.VisualStudio.TraceDataCollector.dll.
148
+
see `DynamicCoverageDataCollector.OnInitialize` for the default configuration logic. The default config is in the resources of Microsoft.CodeCoverage.Core.
146
149
147
150
## Problems with ms code coverage
148
151
@@ -347,7 +350,7 @@ If you are using option 1) then project and global options will only be used whe
347
350
| DisabledNoCoverage | Set to false for VS Option Enabled=false to not disable coverage |
348
351
| RunWhenTestsFail | By default coverage runs when tests fail. Set to false to prevent this. **Cannot be used in conjunction with RunInParallel**|
349
352
| RunWhenTestsExceed | Specify a value to only run coverage based upon the number of executing tests. **Cannot be used in conjunction with RunInParallel**|
350
-
| RunMsCodeCoverage | Change to IfInRunSettings to only collect with configured runsettings. Yes (default) for runsettings generation. No to use Coverlet or OpenCover. |
353
+
| RunMsCodeCoverage | Change to IfInRunSettings to only collect with configured runsettings. Yes (default) for runsettings generation. No to use Coverlet or OpenCover. |
351
354
| IncludeTestAssembly | Specifies whether to report code coverage of the test assembly |
352
355
| IncludeReferencedProjects | Set to true to add all directly referenced projects to Include. |
353
356
| IncludeAssemblies | Provide a list of assemblies to include in coverage. The dll name without extension is used for matching. |
@@ -393,28 +396,34 @@ If you are using option 1) then project and global options will only be used whe
393
396
394
397
## Exclusions and inclusions
395
398
396
-
You probably want to set IncludeReferencedProjects to true. This will ensure that you do not get coverage for testing frameworks - only your code.
397
-
398
399
Coverlet and OpenCover use filter expressions.
399
-
Filter expressions
400
-
401
-
Wildcards
402
-
403
-
\* => matches zero or more characters
404
-
Examples
405
400
406
-
[\*]\* => All types in all assemblies.
407
-
408
-
[coverlet\.\*]Coverlet.Core.Coverage => The Coverage class in the Coverlet.Core namespace belonging to any assembly that matches coverlet.\* (e.g coverlet.core)
401
+
Filter expressions
409
402
410
-
[\*\]Coverlet.Core.Instrumentation.\* => All types belonging to Coverlet.Core.Instrumentation namespace in any assembly
403
+
> Wildcards
404
+
>
405
+
> \* => matches zero or more characters
406
+
>
407
+
> Examples
408
+
>
409
+
> [\*]\* => All types in all assemblies.
410
+
>
411
+
> [coverlet\.\*]Coverlet.Core.Coverage => The Coverage class in the Coverlet.Core namespace belonging to any assembly that matches coverlet.\* (e.g coverlet.core)
412
+
>
413
+
> [\*\]Coverlet.Core.Instrumentation.\* => All types belonging to Coverlet.Core.Instrumentation namespace in any assembly
414
+
>
415
+
> [coverlet\.\*.tests]\* => All types in any assembly starting with coverlet. and ending with .tests
416
+
>
417
+
> Both 'Exclude' and 'Include' options can be used together but 'Exclude' takes precedence.
411
418
412
-
[coverlet\.\*.tests]\* => All types in any assembly starting with coverlet. and ending with .tests
419
+
Ms code coverage uses [regexes](https://learn.microsoft.com/en-us/visualstudio/test/customizing-code-coverage-analysis?view=vs-2022#regular-expressions).
413
420
414
-
Both 'Exclude' and 'Include' options can be used together but 'Exclude' takes precedence.
421
+
> You can include or exclude assemblies or specific types and members from code coverage analysis. If the Include section is empty or omitted, then all assemblies that are loaded and have associated PDB files are included. If an assembly or member matches a clause in the Exclude section, then it is excluded from code coverage. The Exclude section takes precedence over the Include section: if an assembly is listed in both Include and Exclude, it will not be included in code coverage.
415
422
416
-
Ms code coverage uses [regexes](https://learn.microsoft.com/en-us/visualstudio/test/customizing-code-coverage-analysis?view=vs-2022#regular-expressions).
417
-
You can include or exclude assemblies or specific types and members from code coverage analysis. If the Include section is empty or omitted, then all assemblies that are loaded and have associated PDB files are included. If an assembly or member matches a clause in the Exclude section, then it is excluded from code coverage. The Exclude section takes precedence over the Include section: if an assembly is listed in both Include and Exclude, it will not be included in code coverage.
423
+
Just remember that as soon as there is an include for an assembly all other assemblies that you require coverage for will also need to be included. ( [internals](https://github.com/FortuneN/FineCodeCoverage/issues/489) )
424
+
If there are no includes then all assemblies will be included unless explicitly excluded.
425
+
Hence when IncludeTestAssembly is true FCC only explicitly includes it when there are other includes specified.
426
+
**You may want to set IncludeReferencedProjects to true. This will ensure that you do not get coverage for testing frameworks - only your code.**
418
427
419
428
You can ignore a method or an entire class from code coverage by applying the [ExcludeFromCodeCoverage] attribute present in the System.Diagnostics.CodeAnalysis namespace.
420
429
@@ -447,19 +456,19 @@ if you want to contribute to this project.
447
456
For cloning and building this project yourself, make sure
448
457
to install the [Extensibility Essentials](https://marketplace.visualstudio.com/items?itemName=MadsKristensen.ExtensibilityEssentials2022)
449
458
extension for Visual Studio which enables some features
0 commit comments