Daily Usage Issues

Exclude compiler generated code from coverage?

Started by ndeslandes on 7,875 views

Hi,

I love the support for the ExcludeFromCodeCoverage attribute. Is there a way to indicate other attributes that should exclude class and methods from the coverage report?

The main use I would have for it would be to exclude compiler generate code, such as this:


    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
    internal class Resources
    {

        private static global::System.Resources.ResourceManager resourceMan;

        private static global::System.Globalization.CultureInfo resourceCulture;

        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
        internal Resources()
        {
        }

        /// <summary>
        ///   Returns the cached ResourceManager instance used by this class.
        /// </summary>
        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
        internal static global::System.Resources.ResourceManager ResourceManager
        {
            get
            {
                if ((resourceMan == null))
                {
                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("BP.FofToLimUploader.Gui.Properties.Resources", typeof(Resources).Assembly);
                    resourceMan = temp;
                }
                return resourceMan;
            }
        }



Unfortunately this class isn't partial, so I can't manually add the ExcludeFromCoverage attribute, and so it always shows in the NCrunch metrics unless manually excluded in the GUI.
DotCover allows you to add any attribute in the list of attributes that should exclude coverage, which solved this issue quite nicely.

Is there a way to do something similar in NCrunch?

Thanks,

Nico
Hi Nico,

Thanks for sharing this request.

What is your purpose behind excluding this code from NCrunch's coverage? Is it just to try and remove the distortion from the Metrics Window? Or are you trying to improve performance?

If adjusting the metrics is your intention, I recommend using the exclusion filter in the Metrics Window. This can be used to exclude the code at file-level so it will not impact your coverage percentages, alleviating the need for any code changes or attributes.

I'm afraid there's nothing better that I can recommend at this stage.


Cheers,

Remco

Edited

Hi Remco,

Thanks for your reply, which I unfortunately missed...
The main purpose is indeed to remove the distortion from the metric window. I have used Metrics Window filter, which was fine in my case since I'm working on a small-ish project right time.
This would've been much more painful in a very large project, where possibly hundreds of manual exclusions would have to be done by every developer... Being able to automate that with a single configuration setting would be really valuable.

Cheers,

Nico
Thanks Nico - I'll look into it :)

Post a reply

Log in to reply.