

Exclude automatic properties from code coverage in Visual Studio 2015
source link: https://www.codesd.com/item/exclude-automatic-properties-from-code-coverage-in-visual-studio-2015.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Exclude automatic properties from code coverage in Visual Studio 2015
I just upgraded a bunch of projects to VS2015/C#6.
Now MSTest's Code Coverage analysis is reporting that some auto properties aren't covered by unit tests. This wasn't the case in Visual Studio 2013, and I suspect it may be something to do with the new autoproperty features in C#6.
Dealing with all the false-positives this generates rather defeats the purpose of the Code Coverage tool as it makes it practically impossible to identify actual code lacking test coverage. We don't want to write unit tests for all our DTOs, and I'd really rather not have to go through the project annotating every single auto-property with ExcludeFromCodeCoverage
.
I've created a working MCVE at https://github.com/iaingalloway/VisualStudioCodeCoverageIssue
- Open
VisualStudio2013.sln
in Visual Studio 2013 Premium or Ultimate. - Click Test -> Analyze Code Coverage -> All Tests.
- Observe that the "Code Coverage Results" window reports 0 Blocks "Not Covered".
- Open
VisualStudio2015.sln
in Visual Studio 2015 Enterprise. - Click Test -> Analyze Code Coverage -> All Tests.
- Observe that the "Code Coverage Results" window reports 1 Block "Not Covered" (the getter for ExampleDto.Value)
Is it possible to configure the built-in Code Coverage tool in Visual Studio 2015 to ignore auto-properties like Visual Studio 2013 does?
As a workaround, you can add the following to your .runsettings file:-
<RunSettings>
<DataCollectionRunSettings>
<DataCollector ...>
<Configuration>
<CodeCoverage>
<Functions>
<Exclude>
<Function>.*get_.*</Function>
<Function>.*set_.*</Function>
</Exclude>
...
It's not a great workaround, but as long as you aren't using any functions with "get_" or "set_" in the names it should get you the behaviour you need.
Recommend
-
17
A World of Pain? It’s not quite uncommon to see developers despair when doing Visual Studio Extensibility (VSX) work. In addition to a myriad new APIs to learn (which can be pretty intimidating), it seems up-front so alien to the typ...
-
9
Exclude parameter from Parameter Binding in WebAPI By Dan Nemec 23 Oct 2014 Lately I’ve been working on some WebAPI code with ActionFilters that inject parameters into the WebAPI action. For example, we authentic...
-
12
SEM A Google Ads setting allowed advertisers to exclude people of ‘unknown gender’ Employers, landlords and cr...
-
21
Conan 1.36 brings several significant enhancements, including several different enhancements to CMake integration, a new property strategy for cer...
-
13
Exclude lines in less (or journalctl)Skip to main content Exclude lines in less (or journalctl) Published: 23-05-20...
-
10
Magento - SQL command to define & ldquo; Exclude & rdquo; On product images advertisements I'm wondering if there's some SQL command I...
-
6
Shortcut to create properties in Visual Studio? advertisements I have seen some people creating properties in C# really fast, but how did they...
-
5
Automatic Unit Testing in .NET Core plus Code Coverage in Visual Studio Code Sponsored By I was talking to Toni Edward Solarin on Skype yesterday about his open...
-
4
gRPC Meets .NET SDK And Visual Studio: Automatic Codegen On Build By Kirill ‘kkm’ Katsnelson | Tuesday, June 26, 2018 As part of Microsoft’s move towards its cross-platform .N...
-
7
Automatic issue fixing and filtering in Visual Studio Code Friday, September 9th, 2022 at 8:32 am
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK