So, I'm getting more and more engulfed with test driven development these days and the more code I write while thinking tdd, the more decisions it's seems as though I have to make about the extent of testing that I should write. I would like to set kind of a personal policy as to how much unit testing I should write for my own projects, and was wondering if I get some advice as to how what kind of you approach you all take.
Here an example of a decision that I'm currently facing...
I have three classes...
public class User
{
public string Username { get; set; }
public List<Favorite> Favorties { get; set; }
}
public class Favorite
{
public string Username { get; set; }
public int rank { get; set; }
}
public class UserManager
{
public List<Favorite> GetTop5(User user)
{
var qry = from fav in user.Favorties.OrderBy(f => f.rank)
select fav;
return qry.Take<Favorite>(5).ToList();
}
}
I have a data access layer for the User class for which I already have a "GetUser" test setup. As you can see, in my business logic I have a method UserManager.GetTop5() that returns the top 5 favorites for the User that I just pulled out of the db. This method is very simple and currently involves NO external resources or dependencies.
So my question is would you go ahead and write another test for this "GetTop5" function point, even though there's very little chance for failure?
Do you setup a test anyway in case you extend upon the functionality in the future? Or do you think that a test here is excessive?