As I’ve mentioned a few times in this space before, I am a freak when it comes to naming things, so much so that James even gave me the nickname “The Name Nazi” a couple years ago. But in my ever-expanding quest to constantly challenge the way I think, I’ve been peeking at the conventions being used by BDD’ers where underscores tend to be used for test names and fixtures.

As someone with a constant eye on the public API design of everything, I’ve never been a fan of using underscores in method names, and when it comes to public APIs, I definitely believe underscores should not be used. But seeing some of the work Sean and Leon are doing with certain things internally here at Telligent has me re-thinking how I write tests, in particular how I name my tests (this re-thinking is why you hire people smarter than you, but that’s a topic for another day).

You see, with BDD, test names tend to get very long because they describe behavior very explicitly. Many believe that because of this, using standard Pascal-case for test names leads to less readable names than if you used underscores. Take for example the following three test method names:

public void CanGetSuccessReturnCodeFromBlogsEndpoint()
public void CanGetSuccessReturnCodeFromBlogEndpointById()
public void CanGetSuccessReturnCodeFromBlogPostEndpointByKey()
 
All three of those test names are pretty descriptive and kind of lengthy. Now look at them with underscores:
 
public void can_get_success_return_code_from_blogs_endpoint()
public void can_get_success_return_code_from_blog_endpoint_by_id()
public void can_get_success_return_code_from_blog_endpoint_by_key()
 
Do you find these more readable than the Pascal-cased names above? I’ve always considered underscores a bit of noise that is distracting in code, but in this case, I’m starting to reverse that line of thought, at least in terms of test names. For a different look, here’s how the names appear in NUnit GUI:
 
underscores

So for me, I’m going to give underscores in test names a shot and see if it sticks, but what I really want to know is what *you* think. Which way do you prefer, and why?