Comment 1 for bug 692612

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)

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