Reputation: 21
I have a C# project in Visual Studio 2010 for which I am writing unit tests using the unit testing framework. When I view the code coverage results for a test run, the coverage does not include properties. It doesn't show the properties as being either tested or non-tested, as if they aren't important at all. Is there a setting I need to flip to turn on code coverage for properties?
Also note that I have already checked the .testsettings file and nothing is set to be excluded from code coverage, nor have I added any attributes to the classes/properties that would exclude them from coverage.
Upvotes: 2
Views: 1883
Reputation: 12904
Automatic Properties do not appear to get added to Code Coverage, so I would check the implementation of your own properties.
For example, the following code produces 100% code coverage;
namespace ClassLibrary1
{
public class Class1
{
public int Property1 { get; set; }
}
}
[TestMethod]
public void TestMethod1()
{
var test = new Class1();
Assert.IsNotNull(test);
}
Whereas the same test with the following changes to the Class give 40% coverage;
public class Class1
{
private int _property1;
public int Property1
{
get { return _property1; }
set { _property1 = value; }
}
}
Upvotes: 1