25 July 2010

How to change the ReSharper naming style for test methods

For normal methods I use the Pascal casing convention (or UperCamelCase as it is called by ReSharper). But in unit tests readability rules and therefore I use very long names like:

public void MethodUnderTest_Scenario_ExpectedResult()

ReSharper marks them as violating the naming style, which is quite annoying because this distracts from real problems. Luckily there is a way to tell ReSharper to use a different naming convention for test methods. It is a little bit hidden in the ReSharper options, but here is the way to go:

ReSharper Options –> Naming Style –> Advanced settingsimage
In “Affected entities” mark “Test method (property)” and disable inspections.image

Now you have no warnings in your tests anymore that complain of inconsistent naming styles. Naming styles for non test classes and methods are still working as before. This was tested with ReSharper 5.1.


  1. Hi Christian!

    Funny that I came across your blog while trying to solve exactly this problem :-) Thanks for the (obvious) solution.

    Say hi to everybody from me!

    Greetings from Dublin,

  2. Thanks for the post, it's quite helpful.

    Do you have a suggestion about what to do about the names of methods for event handlers that Visual Studio generates when you hit tab after typing += when you want to subscribe to an event?
    e.g: Button1_Clicked


  3. @wtheronjones
    ReSharper has settings for those, in the same "Advanced settings" window that is mentioned in this post.

  4. Thanks for saving my brain from further unnecessary expenditure of effort by relieving it from the task of compensating for this annoyance.

  5. Thanks, this worked fine for me as well - even on ReSharper 6.0.
    Well, it worked, then it stopped working, then I deleted the ReSharper.user file, then it worked again.


  6. Instead of disable inspections for your test classes and methods, you can also add for them aditional naming styles, e.g. "all_lower", or "First_upper" - top rights in your last screenshot

  7. Thanks very much for this. All those wavy blue lines in my test classes were driving me nuts!

  8. Something to note is that the 'Access rights' in the new rule have to include Private if your test classes or methods are private.

  9. Great write-up, I am a big believer in commenting on blogs to inform the blog writers know that they’ve added something worthwhile to the world wide web!.. shoes brand names

  10. Wow, this is fascinating reading. I am glad I found this and got to read it. Great job on this content. I liked it a lot. Thanks for the great and unique info. unique business names

  11. Pretty good post. I have just stumbled upon your blog and enjoyed reading your blog posts very much. I am looking for new posts to get more precious info. Big thanks for the useful info. creative brand names