This one came up in discussion last week and could be worth mentioning.
Consider the following property:
private List<SchemaAttribute> _attributes = new List<SchemaAttribute>();
public List<SchemaAttribute> Attributes
{
get
{
return _attributes;
}
set
{
_attributes = value;
}
}
NCover/NCoverExplorer reliably inform me that this property has only 50% coverage
in my tests.
By hereto unexplored forces of nature, every consumer of this class calls
.Attributes.Add()
or, itterates over it as so:
foreach (SchemaAttribute element in instance.Attributes)
{
// ...
}
The keen eye will notice that neither of these ways to access the property actually hit the setter!
Two possible paths present themselves:
- Write a test that just exercises the setter. This seems to me pointless.
If we are to consider that our tests can serve to express our intention
in a repeatable fashion, what is our intent? To see if a Generic List still works?
- Consider makeing the property read-only. Including braces I could own three lines less code. Yay!
And also now I have had cause to think about it, it's not my intention that the
List be set as a list, for this class it just dosen't make sense right now.
Next step? Consult Francesco & Giuseppe!
Sleep. The best 10 hours of the week.
Listening to: Nick Cave and the Bad Seeds - Abattoir Blues