In lots of tutorials for UnitTesting, the way to mark a TestMethod was different. I saw these options:
[TestMethod]
[TestMethod()]
What is the difference?
With and without brackets its exactly the same:
[TestMethod]
[TestMethod()]
The empty brackets just call the default constructor of that attribute that has no parameters. So does [TestMethod]
.
Both call the default constructor.
This would be different:
[TestMethod(SomeParameter)]
And [Test]
is an attribute that comes from NUnit library and is different from the .Net [TestMethod]
attribute.
[TestMethod(TypeId = "test")]
for example
The empty parentheses are redundant, the two lines are equivalent. Tools such as ReSharper would give you the option of removing this redundancy from your code.
[TestMethod]
[TestMethod()]
Both are same but when Visual Studio auto generate test method it comes with [TestMethod()]
[Test]
attribute belongs toNUnit
Api.