C# Attributes
-
Hi all, I was just reading the following article Introduction to NUnit... and was introduced to Attributes. I'm a noob so I've never seen this before or read about it. I understand that it allows you to define metadata within your program and so on... My question is more so about format than understanding. I was wondering if I put in an attribute right above on function if that attribute is assigned to all functions below it until another attribute is reached. For instance:
[SetUp]
public void init()
{
Person person = new Person();
}public void foo()
{...}Will the attribute [SetUp] be for both init and foo, or just init? Thanks, Jeramy
-
Hi all, I was just reading the following article Introduction to NUnit... and was introduced to Attributes. I'm a noob so I've never seen this before or read about it. I understand that it allows you to define metadata within your program and so on... My question is more so about format than understanding. I was wondering if I put in an attribute right above on function if that attribute is assigned to all functions below it until another attribute is reached. For instance:
[SetUp]
public void init()
{
Person person = new Person();
}public void foo()
{...}Will the attribute [SetUp] be for both init and foo, or just init? Thanks, Jeramy
The [SetUp] attribute was placed above init - consequently, only the function init has that attribute. By the way, with NUnit, you need a [TestFixture] above your class declarartion, a [TestFixtureSetUp] for the test setup method (if availbale), and a [Test] for every actual test method - the attributes differ between Microsoft Test and NUnit. You can use Visual NUnit for running your tests from Visual Studio (has some bugs, but it's still easier than using the NUnit GUI).