Unit Test Coverage is pedantic

I use the Code Analysis tool in Visual Studio 2012. The report seems very pedantic about what is covered, and I have no idea what else can be done to provide more coverage.

The code I'm testing is as follows:

public class Factory<T> : IFactory<T> where T : new()
{
    public T Create()
    {
        return new T();  // This line has only partial coverage.
    }
}

Unit tests:

using System;
using Xunit;
public class Factory_Tests
{
    [Fact]
    public void Constructor_Works()
    {
        var target = new Factory<Exception>();
    }

    [Fact]
    public void Create_ReturnsNewValue()
    {
        var target = new Factory<Exception>();
        var actual = target.Create();
        Assert.NotNull(actual);
    }
}

The report states that the above line has only partial coverage. What I could not verify on this line?

+4
source share
1 answer

Since this is a general method that can take both a reference type and a value type, it wants you to test it with both.

+2
source

Source: https://habr.com/ru/post/1532395/


All Articles