I have MSTest (VS 2012) unit tests where I want to assert that the various properties of an object have the values I want. There are many ways to do this. However my main concern is that if a new property is added to the object, it's easy to overlook updating the unit tests to make sure that it has the values we expect.
One thing I can think of is to use reflection to enumerate the public properties of the object, then keep track of which properties the unit test has asserted, and at the end, assert if any properties did not get checked.
Has anybody already written something similar?
Any better ideas?
Update: I should point out that the objedct in question is something like a Data Transfer Object where there are other classes/methods that cause data in that object to be updated. It's easy to overlook updating the tests for those classes/methods to make sure that we account for all of the object's properties. I want something a bit stronger (i.e. can't be forgotten or overlooked) than right-clicking on the object, finding references, and reviewing the code.
For example:
public class Person {
public string FirstName;
}
public Person GetPerson() {}
[TestMethod]
public void GetPerson_ReturnsFilledInPerson()
{
var actual = target.GetPerson();
Assert.IsNotNull(actual.FirstName);
// If somebody later adds LastName to Person,
// we want this unit test to fail until the LastName is checked too.
}
Thanks,
Dan