c# - 为什么要在 UnitTest 中的 TestMethod 属性上加上括号

标签 c# unit-testing

在许多单元测试教程中,标记 TestMethod 的方式各不相同。我看到了这些选项:

[TestMethod] 
[TestMethod()]

有什么区别?

最佳答案

带括号和不带括号完全一样:

[TestMethod] 
[TestMethod()]

空括号只是调用那个没有参数的属性的默认构造函数。 [TestMethod] 也是如此。 两者都调用默认构造函数。

这会有所不同:

[TestMethod(SomeParameter)]

[Test] 是一个来自 NUnit 库的属性,不同于 .Net [TestMethod] 属性。

关于c# - 为什么要在 UnitTest 中的 TestMethod 属性上加上括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21279006/

相关文章:

c# - 如何使用 TDD 方法创建 Restful Web 服务?

c# - 我怎样才能确保整数除法总是四舍五入?

c# - 如何改变 stub 的行为?

c# - 使用最小起订量模拟 EF DbContext

c# - 使用 Windows Phone 8 连接到 Postgres 数据库

c# - 写入Azure表存储后抛出异常

c# - 更新 jquery 对话框内的 gridview (ASP.net c#)

python - 导入错误: No module named 'app'

Xcode 5 Product -> Test 显示为灰色

c# - 使用 Sitecore FakeDb 模拟 Sitecore 数据库