Comment 2 for bug 692612

Revision history for this message
Michael Schnick (michael-schnick) wrote : RE: [Bug 692612] Re: Feature request: Provide interface to query selected categories

Hi Charlie,

using the TestCaseSource attribute should indeed solve our problem / serve our needs.
In my eyes, you can close the Change Request.

Many thanks :-)

Michael

-----Original Message-----
From: <email address hidden> [mailto:<email address hidden>] On Behalf Of Charlie Poole
Sent: Freitag, 21. Oktober 2011 21:25
To: Schnick, Michael
Subject: [Bug 692612] Re: Feature request: Provide interface to query selected categories

On the surface, this makes sense, but after further analysis there are
some issues...

1. When no categories are selected, all tests are run but
SelectedCategories will be empty. This could be handled by the user
checking for an empty list.

2. Categories may also be excluded. We would need to provide a separate list for these categories and the user would have to test it as well. So the test would become something like...
   If ( TestContext.SelectedCategories.Contains("long") && !TestContext.ExcludedCategories.Contains("long) )...
with added logic to handle empty lists, depending on what the user wanted to accomplish.

3. A category expression may be provided, like A + B - C. This cannot be
expressed as a simple list so the user would be forced to duplicate
NUnit's parsing of the expression. Further, this expression syntax is
likely to change in the next version of NUnit.

I'm open for suggestions on how to deal with these problems, either from
the original proposer or from others.

An alternative is to use the TestCaseSourceAttribute to provide data. We
have recently added a Category property to that attribute, allowing the
example to be rewritten as follows:

IEnumerable shortData = new object[] { item1, item2 };
IEnumerable longData = new object[] { item3, item4, ... , itemN }

[TestCaseSource("longData", Category="long")]
[TestCaseSource("shortData", Category="short")]
Public void SomeTest(List<SomeType> list)
{
 ProcessList(List);
}

This seems to me to solve all the problems and eliminate the need for
the requested feature. Thoughts?

--
You received this bug notification because you are subscribed to the bug
report.
https://bugs.launchpad.net/bugs/692612

Title:
  Feature request: Provide interface to query selected categories

Status in NUnit V2 Test Framework:
  Triaged

Bug description:
  Please implement a feature that will provide a list of which
  categories have been chosen for the test run (using the include list).

  Here's a code sample of how this could be used in future:

  TestContext.SelectedCategories would offer a collection indicating
  which categories were selected.

  [Test]
  [Category("long")]
  [Category("short")]
  Public void SomeTest()
  {
   List.Add(item1);
   List.Add(item2);
   If(TestContext.SelectedCategories.Contains("long"))
   {
    List.Add(item3);
    List.Add(item4);
  ...
    List.Add(itemN);
   }
   ProcessList(List);
  }

  Depending on the content of the list, this test might either take an
  hour (full scope) or 2 minutes (reduced scope).

  This feature request has been filed as a result of a discussion in NUnit discuss group:
  http://groups.google.com/group/nunit-discuss/browse_thread/thread/79a899b9c37866df

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