Agile FAQs
  About   Slides   Home  

 
Managed Chaos
Naresh Jain's Random Thoughts on Software Development and Adventure Sports
     
`
 
RSS Feed

Recent Thoughts
Tags
Recent Comments

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…

Related posts:

  1. Naming Style of my Test Methods is changing…
  2. The I Naming Convention
  3. Smells in Test that indicate Design problems
  4. My reaction to “Nokia Test for Scrum”
  5. More Fluent Interfaces in Test
  • http://developer-in-test.blogspot.com/ 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

    1
    
    AcmeMail -&gt; reset_failed_attempt_count_if_I_successfully_log_in

    .

    1
    
    AcmeMail -&gt; donot_allow_login_if_my_account_is_revoked

    Yes I do use _ instead of camel casing. Is it too extreme? :)

  • http://developer-in-test.blogspot.com 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

    1
    
    AcmeMail -&gt; reset_failed_attempt_count_if_I_successfully_log_in

    .

    1
    
    AcmeMail -&gt; donot_allow_login_if_my_account_is_revoked

    Yes I do use _ instead of camel casing. Is it too extreme? :)

  • http://developer-in-test.blogspot.com/ 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

    1
    
    AcmeMail -&gt; reset_failed_attempt_count_if_I_successfully_log_in

    .

    1
    
    AcmeMail -&gt; donot_allow_login_if_my_account_is_revoked
  • http://developer-in-test.blogspot.com 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

    1
    
    AcmeMail -&gt; reset_failed_attempt_count_if_I_successfully_log_in

    .

    1
    
    AcmeMail -&gt; donot_allow_login_if_my_account_is_revoked
  • http://agilefaqs.com/nareshjain.html Naresh Jain

    @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.

  • http://agilefaqs.com/nareshjain.html Naresh Jain

    @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?

  • 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?

  • http://developer-in-test.blogspot.com/ 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? :)

  • http://developer-in-test.blogspot.com 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.

  • 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.

  • http://agilefaqs.com/nareshjain.html Naresh Jain

    @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:

    <prodClassName>Test – Standard xUnit convention
    Behavior (verbs) as Test Class Names

  • http://agilefaqs.com/nareshjain.html Naresh Jain

    @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:


    Licensed under
Creative Commons License