【问题标题】:What is the difference between the Method attributes TestMethod and TestMethod()?方法属性 TestMethod 和 TestMethod() 有什么区别?
【发布时间】:2015-01-23 12:48:35
【问题描述】:

我正在使用 Visual Studio 单元测试 fwk 为 C# 项目编写单元测试,并发现使用 [TestMethod][TestMethod()] -任何属性工作正常。它们有什么区别?

【问题讨论】:

标签: c# visual-studio-2010 unit-testing


【解决方案1】:

属性可以有参数。如果您不传递任何参数,您可以编写 [TestMethod] 或 [TestMethod()]。

【讨论】:

    【解决方案2】:

    属性可以与我们的不带括号一起使用,尽管似乎普遍的共识是使用它们。

    Can you omit the parenthesis from attributes with no params?

    这种共识很可能是由于“常规”(即非属性)方法必须以 括号调用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-14
      • 2013-11-11
      相关资源
      最近更新 更多