在许多单元测试教程中,标记 TestMethod 的方式各不相同。我看到了这些选项:
[TestMethod]
[TestMethod()]
有什么区别?
最佳答案
带括号和不带括号完全一样:
[TestMethod]
[TestMethod()]
空括号只是调用那个没有参数的属性的默认构造函数。 [TestMethod]
也是如此。
两者都调用默认构造函数。
这会有所不同:
[TestMethod(SomeParameter)]
而 [Test]
是一个来自 NUnit 库的属性,不同于 .Net [TestMethod]
属性。
关于c# - 为什么要在 UnitTest 中的 TestMethod 属性上加上括号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21279006/