Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between the Method attributes TestMethod and TestMethod()?

I am writing unit tests for a C# project using Visual Studio Unit test fwk, and found that using [TestMethod] or [TestMethod()] -any of the attributes work fine. What is the difference between them?

like image 636
Thunderstruck Avatar asked Oct 24 '25 18:10

Thunderstruck


2 Answers

A attribute can have parameters. If you don't pass any parameters you can write [TestMethod] or [TestMethod()].

like image 135
Manuel Amstutz Avatar answered Oct 27 '25 06:10

Manuel Amstutz


Attributes can be used with our without parens, although it seems like the general consensus is to use them.

Can you omit the parenthesis from attributes with no params?

This consensus is most likely due to the fact that "regular" (i.e. non-attribute) methods must be called with parens.

like image 26
rory.ap Avatar answered Oct 27 '25 06:10

rory.ap