| Test Naming: To Underscore or Not To Underscore |
| Tuesday, January 06 2009 |
|
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()
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()
![]() |
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?

