I have three functions:
ValidateUsername()
, which determines if a string is a valid username according to some rulesSetUsername()
which sets a string as a user's Username if it passes validationAddNewUser()
, which creates a new user and, among others, sets a string as his or hers Username usingSetUsername()
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?