AxoCover icon indicating copy to clipboard operation
AxoCover copied to clipboard

Question: exclude .ctor from coverage

Open PaulWilhelmsen opened this issue 7 years ago • 2 comments

Hey, I was wondering if there is a way to exclude .ctor from coverage? I'm using Visual Studio 2017 if it makes any difference.

I have tried to read the documentation, but couldn't find out how to do it. I really appreciate this tool =) It's great and even becomes better the more i learn about it. Thanks!

image

PaulWilhelmsen avatar Nov 07 '18 07:11 PaulWilhelmsen

I dont think it's a good idea to exclude ctor from coverage. we can test if some of dependencies are null or someting else if we are using a constructor dependency injection.

I hope you see what i'm explaining :)

Best regards.

kbourzayq avatar Nov 26 '18 16:11 kbourzayq

Since AxoCover uses OpenCover and OpenCover respects the ExcludeFromCodeCoverageAttribute you can mark your .ctor with ExcludeFromCodeCoverage but I do not recommend it (otherwise you would not know which of your .ctors is covered and which is not.

    public class MyClass
    {
        private Logger logger;

        [ExcludeFromCodeCoverage]
        public MyClass()
        {
            this.logger = new Logger();
        }

        [ExcludeFromCodeCoverage]
        public MyClass(ILogger logger)
        {
            this.logger = logger;
        }
    }

You can change this behaviour in the settings

image

Steinblock avatar May 27 '19 09:05 Steinblock