When writing WebDriver (or other automated tests) we are often faced with dilemma of how to name test method. For ex you may come across following test methods -
- verifyLoginAsValidUser
- verifyLoginAsInvalidUser
- verifyLogoutAndLoginAsUserWhoSavedConsentOnLastLogin
- verifyDefaultTeamSelection
- verifyTeamDisplay
- verifyMembersDisplay
good enough, is not it? And if not then we can add more description about test method either in @description tag when using TestNG or on test method level comments. But what if test names were descriptive enough so that we don't have to resort to any of the other means ? Let's rewrite above mentioned test method names as -
- shouldLoginUserWhenCredentialsAreValid
- shouldNotLoginUserWhenCredentialsAreInvalid
- shouldNotShowConsentScreenWhenConsentWasSavedOnLastLogin
- shouldSelectDefaultTeamOnPageLoad
- shouldDisplayTeamAttributesForSelectedTeam
- shouldDisplayMemberLoginNamesForSelectedTeam
Here in test method names are based on format - Should<expected>_When<condition>. There is extended discussion on this topic on SO
Do you think these method names are more descriptive than what we used earlier? How would you name your test methods?