Feature request: Provide interface to query selected categories

Bug #692612 reported by Michael Schnick
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit V2
Won't Fix
Undecided
Unassigned

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

Tags: feature
Changed in nunitv2:
status: New → Triaged
importance: Undecided → Low
milestone: none → 2.6.0
Revision history for this message
Charlie Poole (charlie.poole) wrote :

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?

Changed in nunitv2:
importance: Low → Undecided
Revision history for this message
Michael Schnick (michael-schnick) wrote : RE: [Bug 692612] Re: Feature request: Provide interface to query selected categories
Download full text (3.2 KiB)

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...

Read more...

Revision history for this message
Charlie Poole (charlie.poole) wrote :

Thanks. I closed it as Won't Fix since nothing else seems to fit.

Changed in nunitv2:
status: Triaged → Won't Fix
Changed in nunitv2:
milestone: 2.6.0 → none
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.