How to use bdd naming style with Resharper 4.5?

廉价感情. 提交于 2019-12-21 07:11:04

问题


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:


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.




回答2:


How to change the ReSharper naming style for test methods




回答3:


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.




回答4:


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).




回答5:


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




回答6:


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.




回答7:


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.




回答8:


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"



来源:https://stackoverflow.com/questions/757381/how-to-use-bdd-naming-style-with-resharper-4-5

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!