Being new to unit testing I would like to know if I am supposed to test the values of objects returned from methods when doing unit testing. As an example, consider the following classes:
public class Person
{
public int Id { get; set }
public int Age { get; set; }
public string Name { get; set; }
public Pet Pet { get; set; }
}
public class Pet
{
public int Id { get; set; }
public int Age { get; set; }
public Breed Breed { get; set; }
}
And a method with the following declaration:
public Person GetPerson(int id) { ... }
I am now curious if I am supposed to create a test that checks to see if the various properties of the Person are correct (GetPerson_PersonFound_PersonHasCorrectName() and so on)? I suspect that I, under normal circumstances, should? All depends on the requirements?
If those properties should be tested, am I then supposed to dig into Pet and check those properties as well? What about going even further, down into Breed? Can add up to quite a few tests quite quickly.
Pet
is as much of the returned object asAge
, so you should test the values in the same circunstancies (that is, the contract of the method forces it to be set to an specific value).