tags:

views:

1150

answers:

8

I just upgraded to Resharper 4.5 and now see that all my BDDish test methods are marked as not conforming to the naming standard. My naming convention is like this:

public void Something_ShouldHaveThisResult()

Resharper doesn't like the underscore in the method. Is there a way to turn this off, just for test methods? I have a normal naming convention for the rest of my code.

+1  A: 

You can use Agent Smith for more precise code naming conventions.

Note: the version for the final R# 4.5 seems not to be compiled yet... but I'm sure it will be there soon.

Lucero
+1 for a great plug-in; there appears to be a bug related to this particular setting, though: http://code.google.com/p/agentsmithplugin/issues/detail?id=94
TrueWill
A: 

On the menu:

Resharper | Options -> Languages -> Common -> Naming Style: remove what ever naming style you want. They should have a "disable" feature, but they don't.

CLaRGe
I'd like to enforce it for everything except for Test Methods though. If I remove the naming style, it will disable it for all methods, right?
Michael Hedgpeth
You might be right. This is new stuff for Resharper so they may update it soon.
CLaRGe
+1  A: 

Hi

You could use

// ReSharper disable InconsistentNaming

// ReSharper restore InconsistentNaming

around the extremities of each class. e.g

// ReSharper disable InconsistentNaming
namespace bob
{
    [TestClass]
    public class MyTestClass
    {
        [TestMethod] 
        public void Test_Test()
        {
        }
    }
}
// ReSharper restore InconsistentNaming

This however will remove all naming warnings, and not just those on the Method name(s).

Steve Brown
+3  A: 

If you want to follow the Microsoft style guide with your non-test code sources - Have you tried using the StyleCop for ReSharper plugin?

As recommended before: disable the internal ReSharper naming rule set or toggle the inspection settings. StyleCop (thus the StyleCop ReSharper plugin) allows inheritance over the Settings.StyleCop files in your solution folder structure. So you are able to check for valid names in the "real" sources, while the analysis of the test code is disabled.

+1  A: 

I've already added a request for this in the ReSharper bug-tracker. You can vote for it.

Joe White
+1 - looks like they're fixing it for the next version! Nicely done!
TrueWill
+1  A: 

There is no need to remove rules. New Rule can be added that accept underscores

Resharper | Options -> Languages -> Common -> Naming Style and add new rule to the bottom "User defined naming rules"

Robert Vuković
It seems that adding rules here then enforces the BDD style naming conventions in your regular code. Unless you have a specific way of setting this up for just the test method names?
MotoWilliams
You are right. I don't use underscores for regular methods so I didn't noticed this.
Robert Vuković
+2  A: 

Resharper 4.5.1 has added this capability. You can now add a new custom naming rule that applies specifically to a test method, and allow it to contain underscores.

Kevin Dente
That is right. Set your default naming style to be what you use in the production code and add a second, non-default rule for your test naming style, so R# doesn't throw a fit when you do use it.
Jay