Here is some code from the TestCentric
GUI, which collects all the categories for display.
public IList<string> GetAvailableCategories()
{
var categories = new Dictionary<string, string>();
CollectCategories(Tests, categories);
var list = new List<string>(categories.Values);
list.Sort();
return list;
}
private void CollectCategories(TestNode test, Dictionary<string, string> categories)
{
foreach (string name in test.GetPropertyList("Category").Split(new[] { ',' }))
if (IsValidCategoryName(name))
categories[name] = name;
if (test.IsSuite)
foreach (TestNode child in test.Children)
CollectCategories(child, categories);
}
public static bool IsValidCategoryName(string name)
{
return name.Length > 0 && name.IndexOfAny(new char[] { ',', '!', '+', '-' }) < 0;
}
I see two ways to go here...
Use this code to create a C# program that writes out the list of categories.
Emulate this code in Powershell.
In either case, you will need to reference the NUnit engine, either directly or through the engine API.
Obviously, it would be possible for nunit3-console.exe
to display a list of categories in the same way, but that's not a current feature.