← Back to team overview

nunit-core team mailing list archive

[Bug 1111590] Re: [Property] attribute doesn't work correctly with [TestCase]

 

What you are trying to do won't work, by design.

First of all, you are using the TestCaseAttribute incorrecty. It is
intended to be used on a method with arguments and supplies those
arguments. Using it on a method without arguments doesn't make a lot of
sense.

Secondly, when a set of test cases is involved, attributes apply to the
method not to the cases. For the attribute to work as you want, C# would
need to allow attributes to apply to other attributes - which it
doesn't.

Generally, where we use attributes on a test, we have to use a property
on a testcase. For example, we use [ExpectedException] on tests and
ExpectedException=typeof(SomeException) on a test case.

In the case of setting general properties, there is no property of
TestCaseAttribute that you can use, although you can set the Category
and Description (i.e. specific well-known properties) of a test case.
The syntax of a C# attribute constructor is too restricted to allow
something more general very easily.

You can set properties, including custom properties, on a test case if
you use the TestCaseSourceAttribute in conjunction with TestCaseData
objects. The fluent syntax of TestCaseData allows you to set multiple,
arbitrary properties on the test case.

Charlie

** Changed in: nunitv2
       Status: New => Invalid

-- 
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.
https://bugs.launchpad.net/bugs/1111590

Title:
  [Property] attribute doesn't work correctly with [TestCase]

Status in NUnit V2 Test Framework:
  Invalid

Bug description:
          [TestCase]
          [Property("ID", "123")]
          public void Test1()
          {
              Assert.AreEqual(1, 1);
          }

          [Test]
          [Property("ID", "124")]
          public void Test2()
          {
              Assert.AreEqual(1, 1);
          }

  Property cannot be retrieved from EventListener class.

  I'm getting my own "ID" property from TestFinished method.
  result.Test.Properties["ID"]
  But this code doesn't work for Test1. For Test2 that's OK.

To manage notifications about this bug go to:
https://bugs.launchpad.net/nunitv2/+bug/1111590/+subscriptions


References