I have three functions:
ValidateUsername(), which determines if a string is a valid username according to some rules
SetUsername()which sets a string as a user's Username if it passes validation
AddNewUser(), which creates a new user and, among others, sets a string as his or hers Username using
All three should fail if the supplied username string is incorrect, yet
ValidateUsername() is where the rules reside. How would I unit test this? Testing validation only in
ValidateUsername() leaves the possibility that someone will mistakenly omit validation and set the username directly in
AddNewUser(). On the other hand, repeating all different validation test cases for all functions seems counterproductive. What's the best practice?