Since it is a generic method that can accept both a reference type and a value type, it wants you test it with both.
Unit Test Coverage is being pedantic
-
17-06-2023 - |
Domanda
I'm using the Analyse Code Coverage tool in Visual Studio 2012. The report appears to be very pedantic about what is covered and I have no idea what else could be done to provide more coverage.
The code I am testing is this:
public class Factory<T> : IFactory<T> where T : new()
{
public T Create()
{
return new T(); // This line has only partial coverage.
}
}
The 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 claims that the line commented above has only partial coverage. What could I have possibly failed to test on this line?
Soluzione
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow