How to Tell ReSharper Underscores Are OK For Tests

Here’s the scenario – you use ReSharper and you want to use BDD style naming in your tests. You know; that style with all those underscores in the test names so that your really long test names are actually readable.  The problem is, ReSharper get’s all upset at you when you do this and throws warnings in your face something like this:

image

Now you could always turn that rule off, but that would mean losing the benefit of picking up bad names in the rest of your code which is not ideal.  What you really want is the best of both worlds (cue Hannah Montana intro music – gah! I blame my 10 year old for that. Sorry).

Anyway, here’s how to configure ReSharper to allow underscores:

Go to ReSharper->Options->Naming Style.  Highlight the Method naming rule and click Edit.

image

Click the Add button and add in a new rule for First_upper as shown here:

image

Now go back and look at your source… It be blue squiggle free. Yay!

image

By the way, if you want to have use naming such as Upper_Case_And_Underscores then you’re out of luck as far as I can tell, since there’s no options I can see to add a new name style to R#.

 

Reader Comments

There has been a big lodged and a workaround posted here: http://youtrack.jetbrains.net/issue/RSRP-186685#comment=27-161684

In short, they're working on it.

This blog post shows another way of doing this specifically for unit test methods:

http://atombrenner.blogspot.com/2010/07/how-to-change-resharper-naming-style.html

You described step by step very clearly. I had understood very well. Thanks for sharing.

Post a Comment



Welcome

Thanks for dropping by. Enjoy your visit!

MVP Logo Visual Studio 2012 Cookbook
Find out more about Richard.

Richard on Twitter  
profile for Richard Banks on Stack Exchange, a network of free, community-driven Q&A sites

User Groups

My Open Source Projects

Podcast

Blog Archive