为什么在UnitTest中将括号放在TestMethod属性上

Joh*_*nny 8 c# unit-testing

在许多关于UnitTesting的教程中,标记TestMethod的方式是不同的.我看到了这些选项:

[TestMethod] 
[TestMethod()]
Run Code Online (Sandbox Code Playgroud)

有什么不同?

Ron*_*Dex 12

有和没有括号,它完全相同:

[TestMethod] 
[TestMethod()]
Run Code Online (Sandbox Code Playgroud)

空括号只调用该属性的默认构造函数,该构造函数没有参数.那样做[TestMethod].两者都调用默认构造函数.

这会有所不同:

[TestMethod(SomeParameter)]
Run Code Online (Sandbox Code Playgroud)

并且[Test]是来自NUnit库的属性,与.Net [TestMethod]属性不同.