question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TestFilter does not support test cases with spaces and special characters

See original GitHub issue

Running “dotnet test” with a test filter for a test case with spaces the following exception occurs:

dotnet test --settings …/…/…/build/.runsettings --no-build --logger “trx;LogFileName=C:\Temp\0.trx” --filter “FullyQualifiedName="BackLook.Apps.WorkInProgress.Specs.Computing work in progress Project.No Workpackages exist"” --no-build

Test run for C:\ws\BackLook\system\App.WorkInProgress\BackLook.Apps.WorkInProgress.Specs\bin\Debug\net48\BackLook.Apps.WorkInProgress.Specs.dll (.NETFramework,Version=v4.8) Microsoft ® Test Execution Command Line Tool Version 16.10.0 Copyright © Microsoft Corporation. All rights reserved.

Starting test execution, please wait… A total of 1 test files matched the specified pattern. An exception occurred while invoking executor ‘executor://nunit3testexecutor/’: Unexpected Word ‘work’ at position 64 in selection expression. Stack trace: at NUnit.VisualStudio.TestAdapter.TestFilterConverter.TestFilterParser.Expect(Token[] valid) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\TestFilterConverter\TestFilterParser.cs:line 252 at NUnit.VisualStudio.TestAdapter.TestFilterConverter.TestFilterParser.Parse(String input) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\TestFilterConverter\TestFilterParser.cs:line 66 at NUnit.VisualStudio.TestAdapter.NUnitTestFilterBuilder.ConvertVsTestFilterToNUnitFilter(IVsTestFilter vsFilter) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnitTestFilterBuilder.cs:line 72 at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunTests(IEnumerable1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 116 at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithSources.InvokeExecutor(LazyExtension2 executor, Tuple2 executorUriExtensionTuple, RunContext runContext, IFrameworkHandle frameworkHandle) at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.<>c__DisplayClass48_0.<RunTestInternalWithExecutors>b__0() at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.<>c__DisplayClass0_0.<Run>b__0() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.PlatformThread.Run(Action action, PlatformApartmentState apartmentState, Boolean waitForCompletion) at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.TryToRunInSTAThread(Action action, Boolean waitForCompletion) at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(IEnumerable1 executorUriExtensionMap, Int64 totalTests)

according to https://docs.microsoft.com/de-de/dotnet/core/testing/selective-unit-tests?pivots=mstest spaces and special characters can be encoded using “url style encoding” but that causes the same exception.

example: --filter “FullyQualifiedName=BackLook.Apps.WorkInProgress.Specs.Computing%20work%20in%20progress%20Project.No%20Workpackages%20exist”

i am using

<PackageReference Include="nunit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />

and “dotnet cli” version 5.0.301

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:4
  • Comments:29 (13 by maintainers)

github_iconTop GitHub Comments

4reactions
plainionistcommented, Oct 20, 2021

as far as i can see in the code the repro would probably sufficient to reproduce the issue, at least i see spaces in the test cases. the question is: how do u execute it. if we call it from “dotnet” CLI with a filter like

“–filter “FullyQualifiedName=<put some test name with spaces here>””

then we would probably get the same issue.

dotnet test --filter “FullyQualifiedName=Unit To Test Input A equals itself”

results in

An exception occurred while invoking executor 'executor://nunit3testexecutor/': Unexpected Word 'To' at position 24 in selection expression.
Stack trace:
   at NUnit.VisualStudio.TestAdapter.TestFilterConverter.TestFilterParser.Expect(Token[] valid) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\TestFilterConverter\TestFilterParser.cs:line 255
   at NUnit.VisualStudio.TestAdapter.TestFilterConverter.TestFilterParser.Parse(String input) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\TestFilterConverter\TestFilterParser.cs:line 66
   at NUnit.VisualStudio.TestAdapter.NUnitTestFilterBuilder.ConvertVsTestFilterToNUnitFilter(IVsTestFilter vsFilter) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnitTestFilterBuilder.cs:line 73
   at NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 116
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithSources.InvokeExecutor(LazyExtension`2 executor, Tuple`2 executorUriExtensionTuple, RunContext runContext, IFrameworkHandle frameworkHandle)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(IEnumerable`1 executorUriExtensionMap, Int64 totalTests)

putting the test name in quotes gives similar issues

dotnet test --filter "FullyQualifiedName=\"Unit To Test Input A equals itself\""
dotnet test --filter "FullyQualifiedName='Unit To Test Input A equals itself'"
2reactions
plainionistcommented, Oct 14, 2021

@OsirisTerje I just updated VS to 16.11.5 and the problem still exists. I also doubt that the issue is related to VS but to unit3-vs-adapter. as described above my use case is NOT running tests with spaces in VS itself but on the console using dotnet CLI. The error message clearly indicates that the filter parser is not supporting my use case:

An exception occurred while invoking executor ‘executor://nunit3testexecutor/’: Unexpected Word ‘work’ at position 64 in selection expression. Stack trace: at NUnit.VisualStudio.TestAdapter.TestFilterConverter.TestFilterParser.Expect(Token[] valid) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\TestFilterConverter\TestFilterParser.cs:line 252 at NUnit.VisualStudio.TestAdapter.TestFilterConverter.TestFilterParser.Parse(String input) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\TestFilterConverter\TestFilterParser.cs:line 66 at NUnit.VisualStudio.TestAdapter.NUnitTestFilterBuilder.ConvertVsTestFilterToNUnitFilter(IVsTestFilter vsFilter) in D:\repos\NUnit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnitTestFilterBuilder.cs:line 72

==> pls reopen the issue

thx

Read more comments on GitHub >

github_iconTop Results From Across the Web

Filter dotnet test when the F# test name contains a space ...
You may workaround it by using the "contains"( ~ ) operator (implied for FQDNs) and replacing all spaces (or other invalid characters) with ......
Read more >
Test Selection Language
Some of the characters used in the expression, such as space, | or &, may have a special meaning ... See below for...
Read more >
TestFilter
All characters are either a digit (0-9) or a letter (a-z, A-Z). White space, nulls, control codes, punctuation, and accented or extended characters...
Read more >
Filter and pattern syntax - Amazon CloudWatch Logs
You can test filter patterns in the CloudWatch console. The following examples contain code snippets that show how you can use filter patterns...
Read more >
Allow spaces or special characters as a test name ...
states, "The test name may not contain spaces, quotes, or other characters special in CMake syntax." However, the ability to have such special...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found