Agile FAQs
  About   Slides   Home  

 
Managed Chaos
Naresh Jain’s Random Thoughts on Software Development and Adventure Sports
     
`
 
Discovering...
Industrial Logic

Microblog Feed
    Previous Feeds...
    Recent Thoughts

    Recent Comments
    Categories
    Archives
    June 2009
    M T W T F S S
    « May   Jul »
    1234567
    891011121314
    15161718192021
    22232425262728
    2930  
    RSS Feed
    Add to Technorati Favorites

    My Test Naming Conventions: More Examples

    Other’s Naming Convention My Naming Convention
    itShouldSetAccountToLoggedInWhen-
    PasswordMatches
    matchingPasswordLogsYouIn
    itShouldSetAccountToRevokedAfterThree-
    FailedLoginAttempts
    threeFailedLoginAttemptsRevokesYourAccount
    itShouldNotSetAccountLoggedInIf-
    PasswordDoesNotMatch
    nonMatchingPasswordDoesNotLogYouIn
    itShouldNotRevokeSecondAccountAfterTwo-
    FailedAttemptsFirstAccount
    failedLoginAttemptsOnOtherAccountsDoes-
    NotImpactMyAccount
    itShouldNowAllowConcurrentLogins sameUserCannotLoginConcurrently
    itShouldThrowExceptionIfAccountNotFound onlyUserWithExistingAccountCanLogin
    ItShouldNotBePossibleToLogIntoRevokedAccount userWithRevokedAccountCannotLogin
    itShouldResetBackToInitialStateAfter-
    SuccessfulLogin
    successfulLoginResetsFailedAttemptCount

    So why do I prefer calling my test as nonMatchingPasswordDoesNotLogYouIn instead of itShouldSetAccountToLoggedInWhenPasswordMatches?

    • I think the latter is focusing on implementation details versus focusing on the intent.
    • One should write descriptive names, but the longer the name is, that much more difficult it is to read. I want to write my test names such that they are short and concise. Hence I think the whole itShould<> thing seems repetitive without adding much value.

    More about my test naming convention here…

    • Share/Bookmark
    • Sai
      An important question is how you refer your test class names. I prefer to names them as same as production class names. Example (taking yours to avoid confusion) if you are writing a mail app (AcmeMail) so I would name test as

      AcmeMail -> reset_failed_attempt_count_if_I_successfully_log_in
      .
      AcmeMail -> donot_allow_login_if_my_account_is_revoked

      Yes I do use _ instead of camel casing. Is it too extreme? :)
    • Sai
      okay... The font for the code isn't great. If you use a electron microscope it may be visible as a nano particle in it. One more try and I promise this is the last one


      AcmeMail -> reset_failed_attempt_count_if_I_successfully_log_in
      .
      AcmeMail -> donot_allow_login_if_my_account_is_revoked
    • @Sai, I don't mind the underscore. They can make the code more readable. However I find that typing an underscore is a bit more painful than typing a capital letter. Hence I prefer sticking with the Camel Case.
    • Blaise Pascal
      So why do I prefer calling my test as nonMatchingPasswordDoesNotLogYouIn instead of itShouldSetAccountToLoggedInWhenPasswordMatches?

      I find your reasons reasonable, but incomplete.  Why would you rename itShouldSetAccountToLoggedInWhenPasswordMatches to nonMatchingPasswordDoesNotLogYouIn instead of matchingPasswordLogsYouIn?
    • Sai
      Well the question was not just for camel case (its a carry forward from ruby) also for naming the test class and test method names.

      So if others name as itShouldSetAccountToLoggedInWhenPasswordMatches and you as nonMatchingPasswordDoesNotLogYouIn, I tend to name it as AcmeMail -> logs_you_in_when_passwords_when_passwords_match. The name tends to be descriptive and doesn't have implementation details. I see logging in when password matches and not logging in when password don't match as two different things.

      Also I agree with Blaise Pascal (Is it really Pascal? :)
    • Blaise Pascal
      Sai:

      I've been using the name Blaise Pascal online for over a quarter century.  It's not what it says on my legal documentation, but it's real enough.
    • @Pascal, Good catch. That was a Ctrl+C Ctrl+V error. Fixed it now.

      @Sai, very interesting. I've never used the same test class name as the production class name. If I were to do so, I would have to use a different namespace/package. I'm old school and tend to put my test classes in the same package as the production classes. The main reason I do so is, I usually have only one public class in a package public and rest of the classes are package protected (package level visibility). So when I drive their implementation by writing tests, I need to put my tests in the same package.

      There are 2 main styles I use when it comes to naming tests:
      <ul>
      <li><prodClassName>Test - Standard xUnit convention </li>
      <li>Behavior (verbs) as Test Class Names</li>
      </ul>
    blog comments powered by Disqus
        Licensed under
    Creative Commons License
    Design by vikivix