Domanda

I've recently become very interested in improving my project's test coverage. At this point, I have a submodule pretty thoroughly tested, but it's coverage is still pretty low because the tool is picking up all of my views as entirely uncovered. (I'm using MVP, so these views are really "dumb", they don't need to be tested in my opinion.) Before I go slapping an [ExcludeCodeCoverage] attributes on my views, I'd like to know if there are any downsides to this.

To be clear about things, I'm only looking to do this at the class level. For example, I have a method that hits the file system. Obviously, I can't test it (easily), but I consider the fact that I can't test it a smell. Since it's a smell, the reduced coverage on this class is an alert to me that there's something in need of refactoring. I will not be excluding anything "just to get the numbers up". I'm just interested potential pitfalls of excluding the UI layer and simple class factories like this.

public class SourceControlProviderFactory : ISourceControlProviderFactory
{
    public ISourceControlProvider CreateProvider(VBProject project)
    {
        return new GitProvider(project);
    }

    public ISourceControlProvider CreateProvider(VBProject project, IRepository repository)
    {
        return new GitProvider(project, repository);
    }
}

This question is closely related, but I've already targeted the code I'd like to exclude. I'm more interested in "Are there good reasons not to do this?" as opposed to "What should I exclude?".

È stato utile?

Soluzione

What are the cons to excluding some code from coverage analysis?

  1. You don't get to see that code in your code coverage report. So if the coverage changes, you won't know about it (from this tool), so you won't fix it.

  2. Some of your... less disciplined programmers (which may be you in the future) will be more inclined to exclude code if they see other places which are excluded.

But the attribute is there for a reason. Some code, you just don't care if it has test coverage because it's obviously correct, or because it clutters up your report, making it harder to see things that actually are missing coverage. So use it judiciously, and make sure that others do as well.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
scroll top