I have a class (of many) that have properties. Some have logic in them and some don't. Assuming I want to test these properties, how do I go about doing that?
Recently, I've been interested in BDD style for creating unit tests.
So I'd do a setup of the context - basically create the SUT and load up whatever is needed. Then in each Observation (test method), I'd verify that a particular property contains what it should contain.
Here's my question. If the SUT has 20 properties, then do I create 20 Observations/Tests? Could be more if one of the properties contained more interesting logic I guess.
[Observation]
public void should_load_FirstName()
{
Assert.Equals<string>("John", SUT.FirstName);
}
[Observation]
public void should_load_LastName()
{
Assert.Equals<string>("Doe", SUT.LastName);
}
[Observation]
public void should_load_FullName()
{
Assert.Equals<string>("John Doe", SUT.FullName);
}
But would it be better if aggregated the simple ones in a single observation?
[Observation]
public void should_load_properties()
{
Assert.Equals<string>("John", SUT.FirstName);
Assert.Equals<string>("Doe", SUT.LastName);
Assert.Equals<string>("John Doe", SUT.FullName);
}
Or what if I used a custom attribute (that can be applied multiple times to a method). So that I can possible do, something like:
[Observation(PropertyName="FirstName", PropertyValue="John")]
[Observation(PropertyName="LastName", PropertyValue="Doe")]
[Observation(PropertyName="FullName", PropertyValue="John Doe")]
public void should_load_properties()
{
}