Why put parentheses in the TestMethod attribute in UnitTest

In many tutorials for UnitTesting, the way to mark TestMethod was different. I saw the following options:

[TestMethod] [TestMethod()] 

What is the difference?

+7
c # unit-testing
source share
3 answers

With and without parentheses its exactly the same:

 [TestMethod] [TestMethod()] 

Empty brackets simply call the default constructor of this attribute, which has no parameters. Thus, [TestMethod] . Both are called by default constructor.

That would be different:

 [TestMethod(SomeParameter)] 

And [Test] is an attribute that comes from the NUnit library and is different from the .Net attribute [TestMethod] .

+11
source share

Empty parentheses are redundant, two lines are equivalent. Tools like ReSharper will provide you with the ability to remove this redundancy from your code.

+1
source share
 [TestMethod] [TestMethod()] 

Both are the same, but when Visual Studio automatically generates a test method, it comes with [TestMethod()]

+1
source share

All Articles