单元测试有哪些流行的命名约定? [英] What are some popular naming conventions for Unit Tests?

查看:217
本文介绍了单元测试有哪些流行的命名约定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  • 所有测试均遵循相同的标准.
  • 要清楚每种测试状态是什么.
  • 请具体说明预期的行为.

1)MethodName_StateUnderTest_ExpectedBehavior

1) MethodName_StateUnderTest_ExpectedBehavior

Public void Sum_NegativeNumberAs1stParam_ExceptionThrown() 

Public void Sum_NegativeNumberAs2ndParam_ExceptionThrown () 

Public void Sum_simpleValues_Calculated ()

来源:单元测试的命名标准

2)用下划线分隔每个单词

2) Separating Each Word By Underscore

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

其他

  • 使用 Test
  • 结束方法名称
  • 以类名开头的方法名
  • Other

    • End method names with Test
    • Start method names with class name
    • 推荐答案

      在这个男人身上,我与你非常相处.您使用的命名约定是:

      I am pretty much with you on this one man. The naming conventions you have used are:

      • 清除每个测试状态是什么.
      • 具体说明预期的行为.

      您还需要测试名称吗?

      雷的答案相反,我认为测试前缀是必需的.这是测试代码,我们知道.如果您需要这样做来标识代码,那么您会遇到更大的问题,您的测试代码不应与您的生产代码混淆.

      Contrary to Ray's answer I don't think the Test prefix is necessary. It's test code, we know that. If you need to do this to identify the code, then you have bigger problems, your test code should not be mixed up with your production code.

      关于下划线的长度和用途,它的测试代码,到底谁在乎?只要您和您的团队都能看到它,只要它可读性强,并且清楚测试的内容,那就继续吧! :)

      As for length and use of underscore, its test code, who the hell cares? Only you and your team will see it, so long as it is readable, and clear about what the test is doing, carry on! :)

      也就是说,我对测试还是很陌生,并且

      That said, I am still quite new to testing and blogging my adventures with it :)

      这篇关于单元测试有哪些流行的命名约定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆