I’m working on a new project and I’m using the repository pattern, I have my repository that pulls the data from the database and a ‘service’ class which uses the repository and does all the business logic.
something similar to the following;
public class UserRepository : IUserRepository { public IQueryable<User> GetUsers() { // do stuff } } public class UserService { public IList<User> GetUserById { var rep = new UserRepository(); var users = rep.GetUsers(); // do business logic return users.ToList(); } }
Would you test both the UserService and the UserRepository or do you think testing just the Service would suffice? I figure since the service is using the repository it should be fun, but it does kill code coverage.
You should test them both, because it’s possible that someday there will be other clients of UserRepository than UserService, and those clients may use UserRepository differently than UserService.