一般
- 
对所有测试遵循相同的标准。
- 
清楚每个测试状态是什么。
- 
具体说明预期的行为。
例子
1)MethodName_StateUnderTest_ExpectedBehavior
| 12
 3
 4
 5
 
 | Public void Sum_NegativeNumberAs1stParam_ExceptionThrown() 
 Public void Sum_NegativeNumberAs2ndParam_ExceptionThrown ()
 
 Public void Sum_simpleValues_Calculated ()
 | 
资料来源:单元测试的命名标准
2)通过下划线分离每个单词
| 12
 3
 4
 5
 
 | Public void Sum_Negative_Number_As_1st_Param_Exception_Thrown() 
 Public void Sum_Negative_Number_As_2nd_Param_Exception_Thrown ()
 
 Public void Sum_Simple_Values_Calculated ()
 | 
其他
我和你在这一个人身上非常相似。您使用的命名约定是:
您还需要一个测试名称?
与Ray的回答相反,我不认为测试前缀是必要的。它是测试代码,我们知道。如果您需要这样做以识别代码,那么您遇到了更大的问题,您的测试代码不应与您的生产代码混淆。
至于下划线的长度和使用,它的测试代码,谁在乎呢?只有您和您的团队才能看到它,只要它是可读的,并且清楚测试正在做什么,继续! :)
也就是说,我仍然很擅长测试和博客我的冒险经历:)
这也值得一读:构建单元测试
The structure has a test class per class being tested. That’s not so unusual. But what was unusual to me was that he had a nested class for each method being tested.
例如
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 
 | using Xunit;
 public class TitleizerFacts
 {
 public class TheTitleizerMethod
 {
 [Fact]
 public void NullName_ReturnsDefaultTitle()
 {
 // Test code
 }
 
 [Fact]
 public void Name_AppendsTitle()
 {
 // Test code
 }
 }
 
 public class TheKnightifyMethod
 {
 [Fact]
 public void NullName_ReturnsDefaultTitle()
 {
 // Test code
 }
 
 [Fact]
 public void MaleNames_AppendsSir()
 {
 // Test code
 }
 
 [Fact]
 public void FemaleNames_AppendsDame()
 {
 // Test code
 }
 }
 }
 | 
这就是为什么:
Well for one thing, it’s a nice way to keep tests organized. All the
  tests (or facts) for a method are grouped together. For example, if
  you use the CTRL+M, CTRL+O shortcut to collapse method bodies, you can
  easily scan your tests and read them like a spec for your code.
我也喜欢这种方法:
MethodName_StateUnderTest_ExpectedBehavior
所以也许适应:
StateUnderTest_ExpectedBehavior
因为每个测试都已经在嵌套类中
 
我倾向于使用MethodName_DoesWhat_WhenTheseConditions的约定,例如:
| 1
 | Sum_ThrowsException_WhenNegativeNumberAs1stParam | 
但是,我看到很多是让测试名称遵循单元测试结构
这也遵循BDD / Gherkin语法:
这将是以下列方式命名测试:UnderTheseTestConditions_WhenIDoThis_ThenIGetThis
所以你的例子:
| 1
 | WhenNegativeNumberAs1stParam_Sum_ThrowsAnException | 
但是我更喜欢首先测试方法名称,因为测试可以按字母顺序排列,或按字母顺序排列在VisStudio的成员下拉框中,并且1方法的所有测试都组合在一起。
在任何情况下,我喜欢用下划线分隔测试名称的主要部分,而不是每个单词,因为我认为这使得更容易阅读并获得测??试点。
换句话说,我喜欢:Sum_ThrowsException_WhenNegativeNumberAs1stParam优于Sum_Throws_Exception_When_Negative_Number_As_1st_Param。
我使用"PascalCasing"命名我的测试方法,就像其他方法一样,没有任何下划线或分隔符。我将方法的postfix Test留下,因为它没有添加任何值。该方法是一种测试方法,由TestMethod属性指示。
| 12
 3
 4
 
 | [TestMethod]public void CanCountAllItems() {
 // Test the total count of items in collection.
 }
 | 
由于每个Test类只应测试另一个类,因此我将该类的名称留在方法名称之外。包含测试方法的类的名称被命名为使用后缀"Tests"测试的类。
| 12
 3
 4
 
 | [TestClass]public class SuperCollectionTests(){
 // Any test methods that test the class SuperCollection
 }
 | 
对于测试不可能的异常或操作的方法,我在测试方法前加上单词Can not。
| 12
 3
 4
 5
 
 | [TestMethod][ExpectedException(typeOf(ArgumentException))]
 public void CannotAddSameObjectAgain() {
 // Cannot add the same object again to the collection.
 }
 | 
我的命名对话基于Bryan Cook的文章"TDD提示:测试命名约定和指南"。我发现这篇文章非常有帮助。
第一组名称对我来说更具可读性,因为CamelCasing将单词和下划线分开命名方案的各个部分。
我也倾向于在函数名称或封闭的命名空间或类中包含"Test"。
只要你遵循一个练习,它就没关系。通常,我为一个方法编写单个单元测试,该方法涵盖方法的所有变体(我有简单的方法;)然后为需要它的方法编写更复杂的测试集。因此,我的命名结构通常是测试(来自JUnit 3的保留)。
 
我为测试命名空间,类和方法使用'T'前缀。
我尝试整洁并创建复制命名空间的文件夹,然后为测试创建测试文件夹或单独的项目,并复制基本测试的生产结构:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 
 | AProjObjects
 AnObj
 AProp
 Misc
 Functions
 AFunc
 Tests
 TObjects
 TAnObj
 TAnObjsAreEqualUnderCondition
 TMisc
 TFunctions
 TFuncBehavesUnderCondition
 | 
我可以很容易地看出某些东西是一个测试,我确切地知道它所属的原始代码,(如果你不能解决这个问题,那么测试太复杂了)。
它看起来就像接口命名约定(我的意思是,你不会对以'我'开头的事情感到困惑,你也不会对'T'感到困惑)。
无论是否进行测试,都可以轻松编译。
无论如何,它在理论上都很好,对小型项目也很有效。