To reproduce this install the tool.
dotnet new tool-manifest
dotnet tool install NUnit.ConsoleRunner.NetCore --version 3.12.0-beta2
Make a test with a category with spaces in it.
[Test, Category("Multiple Word Category")]
public void MyTestWithCategoryMultipleWords()
{
//test contents
Console.WriteLine("Does this test run with multiple words?");
}
[Test, Category("OneWordCategory")]
public void MyTestWithCategoryOneWord()
{
//test contents
Console.WriteLine("Does this test run with one word?");
}
The test with one word works from the command line and the test with multiple words does not work from the commandline.
Here is what I am running in the commandline:
dotnet nunit TestAutomation/bin/Debug/netcoreapp3.1/TestAutomation.dll --where "cat == Multiple Word Category"
dotnet nunit TestAutomation/bin/Debug/netcoreapp3.1/TestAutomation.dll --where "cat == OneWordCategory"
Here is the output I get from commandline.
NUnit Console Runner 3.12.0-beta2
Copyright (c) 2021 Charlie Poole, Rob Prouse
Sunday, April 11, 2021 11:24:38 AM
Runtime Environment
OS Version: Microsoft Windows 10.0.19042
Runtime: .NET Core 3.1.13
Test Files
NapiAutomation/bin/Debug/netcoreapp3.1/NapiAutomation.dll
Test Filters
Where: cat == Multiple Word Category
Unexpected token 'Word' at position 16 in selection expression.
dotnet --version says 5.0.201
NuGet version 5.7.0.6726
csproj .net version:
NUnit package version:
also this reference:
Windows 10 running from bash or command line gives same result.
This is not related to .NET Core. One gets the same behaviour using the regular console and targeting e.g. framework 4.7.2. But I can make the filtering work by quoting the category - like
.\nunit3-console.exe TEST.dll --where "cat == 'Multiple Word Category'"
I've not updated the labels as I'm unsure if we should handle this better in the filtering code (automatically quoting sequnces with spaces, but this could break/affect existing users), perhaps we should also add some more text to the documentation
https://docs.nunit.org/articles/nunit/running-tests/Test-Selection-Language.html#usage-on-the-command-line
FWIW I don't believe we ever _intentionally_ supported spaces in either the framework or the console runner, although it may have worked in some cases. In NUnit V2 the characters were restricted - for example '-' didn't work - but we never validated that in the constructor. With NUnit 3 we removed existing restrictions.
We could ask for the framework to disallow spaces, but maybe it's better to just document what you have to do when working with them. I don't think we should do any automatic quoting because _where_ expressions can be arbitrarily complex and I doubt we'll easily catch all the odd cases.
Documentation would be great.
I see why I was led to believe I didn't need single quotes around the Category.
I was using Nant before and now I am running it myself from the command line in a Azure Devops Pipeline so I won't be using Nant plus it isn't working with .net core yet.
Here is what I used to run it in Nant using .net framework 4.
<target name="nunitWithCategoryWebQA">
<echo message="Running Automationframework method: ${categoriesToRun}" />
<exec program="${nunit3Dir}" failonerror="true">
<arg value="${buildDir}\WebQa.dll" />
<arg value="--x86" />
<arg value="--result:${buildDir}\${WebQATestResults};format=nunit2" />
<arg value="--where "cat==${categoriesToRun}"" />
</exec>
</target>
I think Nant was adding the single quotes around ${categoriesToRun} and I didn't realize it.