Issue with test filtering
That's what I'm trying to find out I guess. It seems that the fix to the problem was to revert the name changes that was done:
// This causes compatibility problems with older runners.
// return string.IsNullOrWhiteSpace(this.TestMethod.ManagedMethodName)
// ? this.TestMethod.Name
Even now the display name code still has above code, but other code has been added to the ToTestCase() function to append some more information.
Basically, MSTest.TestAdapter version 2.1.0 had this output: vstest.console.exe /TestCaseFilter:"FullyQualifiedName=Namespace.TestName"
Whereas, MSTest.TestAdapter version 3.0.0 had this output: vstest.console.exe /TestCaseFilter:"FullyQualifiedName=Namespace.TestName (input)"
Which causes the error "##[error]Incorrect format for TestCaseFilter Missing Operator '|' or '&'. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed."
So i'm guessing that the failed test function name being returned to the ADO Task now has (input) which is causing it to fail.
So is this an ADO Task issue where they now have to escape the parenthesis? For example, vstest.console.exe /TestCaseFilter:"FullyQualifiedName=Namespace.TestName \(input)\"
Originally posted by @iesmat in https://github.com/microsoft/testfx/issues/793#issuecomment-1372546543
@iesmat I have created the issue so we can investigate.
Thanks @Evangelink!
Hi @iesmat,
Sorry for the delay in investigating this issue. I think I will need a reproducer from you because I don't manage to get the same error.
Could you confirm that if you create a new MSTest test project, bump MSTest versions to 3.0.2 and Test SDK to 17.4.1:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.1" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>
</Project>
use the following code:
namespace TestProject11
{
[TestClass]
public class UnitTest1
{
[TestMethod]
[DataRow(1, "foo")]
public void TestMethod1(int i, string s)
{
}
}
}
and run the following command: dotnet test --filter "FullyQualifiedName=TestProject11.UnitTest1.TestMethod1"
you have 1 test passed?

This indicates that the FullyQualifiedName didn't change
Thanks @Evangelink , i'll try and find a repro for this and comment back.
Hey, not sure if this detail will be of any assistance, but found this post while searching on a similar error. I've seen same result in my ADO pipeline with the VSTest@2 task. Mine is a legacy .NET framework project with tests written in xunit, and for me the format with parenthesis appeared only when I had the task set to retry failed tests, and one of the tests that failed happen to be a Theory with multiple InlineDataAttributes. Below is a bit of scrubbed output from my ADO console, trying to focus on what seems relevant. The initial Passed/Failed messages do appear to be outputting without issue, including the correctly formatted parameters, but the generated TestCaseFilter that looks to target only failed tests is not properly escaped.
{....}
Passed MY.TestA.Test1 [177 ms]
Failed MY.TestA.Test2 [7 ms]
Failed MY.TestB.Test1(paramA: 1, paramB: 0) [70 ms]
Error Message:
System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
{....}
Failed MY.TestB.Test1(paramA: 2, paramB: 1) [70 ms]
Error Message:
System.NullReferenceException : Object reference not set to an instance of an object.
Stack Trace:
{....}
Passed {....}
{....}
Total failed tests as returned by TCM: 23.
Found 2 filtered test case sources.
**************** Rerunning failed tests for Test run 1085156 *********************
Max attempts: 1; Current attempt: 1; Failed test cases threshold: 30; Failed test cases max limit: 0
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\Extensions\TestPlatform\vstest.console.exe "@D:\agent\_work\_temp\3spnhn1ge5c.tmp"
Microsoft (R) Test Execution Command Line Tool Version 16.11.0
Copyright (c) Microsoft Corporation. All rights reserved.
vstest.console.exe /TestCaseFilter:"FullyQualifiedName=MY.TestA.Test2|FullyQualifiedName=MY.TestB.Test3 (6a6588622987a2488df9d40a447484a10c20e555)|FullyQualifiedName=MY.TestB.Test3 (526be715a44d1c4f0d735e87418027080f88637b)"
"D:\agent\_work\13\s\MY.TestA\bin\Integration\MY.TestA.dll"
"D:\agent\_work\13\s\MY.TestB\bin\Integration\MY.TestB.dll"
/Settings:"D:\agent\_work\_temp\xognhhzhu3j.tmp.runsettings"
/Logger:"trx"
/TestAdapterPath:"D:\agent\_work\13\s\packages"
Starting test execution, please wait...
A total of 2 test files matched the specified pattern.
[xUnit.net 00:00:00.2926557] Discovering: MY.TestA
[xUnit.net 00:00:00.3233023] Discovering: MY.TestB
##[error][xUnit.net 00:00:02.8218457] MY.TestA: Exception discovering tests: Incorrect format for TestCaseFilter Missing Operator '|' or '&'. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed.
[xUnit.net 00:00:02.8261092] Discovered: MY.TestA
##[error][xUnit.net 00:00:02.9800610] MY.TestB: Exception discovering tests: Incorrect format for TestCaseFilter Missing Operator '|' or '&'. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed.
[xUnit.net 00:00:02.9839340] Discovered: MY.TestB
{....}
Hope this helps in some way
Yes thank you very much, that is the same error i am getting.
It seems that the VSTest Task is using "vstest.console.exe" instead of the "dotnet test". Not sure if that matters.
But the key is that the filter passed in contains the failed parameter or some identifier in parenthesis.
Sorry I haven't been able to get time to create a repro myself. But the above is exactly what happens.
@iesmat Are you also using version 16.11.0?
@Evangelink , no our command line tool version is 17.4.0 with MSTest.TestAdapter and MSTest.TestFramework version 3.0.0 and Microsoft.NET.Test.Sdk version 17.3.1: "Microsoft (R) Test Execution Command Line Tool Version 17.4.0 (x64) Copyright (c) Microsoft Corporation. All rights reserved."
All the info so far seem to exclude entirely mstest and indicates a problem either in vstest or Azure DevOps tasks. I will move it to vstest but I think we would need a repro to be able to do anything.
The error above about missing | or & operator is caused by ( ) not being escaped, so the filter interpreter thinks they are part of the filter, and not part of the name. And so it expected an operator before them.
When you escape ( ) it still does not work because the FullyQualified name probably does not include the parameters.
// file UnitTest1.cs
namespace mstest63;
[TestClass]
public class UnitTest1
{
[TestMethod]
[DataRow(1)]
[DataRow(2)]
public void TestMethod1(int a)
{
}
}
// file Usings.cs
global using Microsoft.VisualStudio.TestTools.UnitTesting;
dotnet vstest S:\t\mstest63\bin\Debug\net8.0\mstest63.dll
/testcaseFilter:"FullyQualifiedName~2"
Should run the second test if there was the parameter in the name, but it runs 0 tests.
Name runs 1 test correctly, but does not allow to specify the test with fully qualified name.
dotnet vstest S:\t\mstest63\bin\Debug\net8.0\mstest63.dll
/testcaseFilter:"Name~2"
And DisplayName filter just plain does not work because it runs 0 tests even when I look for 1 which is in all test names.
For XUnit, similarly FullyQualified name is not including the parameters, DisplayName filter works and allows to run just one test with the fully qualified name, and Name filter does not work at all.
This is how mstest shows the tests on discovery:
The following Tests are available:
TestMethod1 (1)
TestMethod1 (2)
This is how xunit shows them:
The following Tests are available:
xunit11.UnitTest1.Test1(a: 1)
xunit11.UnitTest1.Test1(a: 2)
Xunit implementation of DisplayName filter seems to be consistent with what is shown on discovery. MSTest seems not.
Not being able to use DisplayName on mstest, and Name on xunit is explained by this table:

Thed don't support them. The filterExpression is probably generic and not throwing on unknown identifier because the filter can contain filters that are specific to multiple frameworks, to allow filtering for a multi-test-framework solution.
https://github.com/Microsoft/vstest-docs/blob/main/docs/filter.md
@Evangelink this seems to be mstest problem. The filter is passed correctly once () are escaped correctly.
Maybe the error message in vstest could be improved a bit to point out that literal ( ) need to be escaped. WYDT?
If I try to summarize here. Given the test class:
[TestClass]
public class UnitTest1
{
[TestMethod]
[DataRow(1)]
[DataRow(2)]
public void TestMethod1(int a)
{
}
}
You can do:
-
dotnet test --filter "FullyQualifiedName=TestProject2.UnitTest1.TestMethod1"which will run the 2 tests because they both have the same fully qualified name (parameters are ignored). -
dotnet test --filter "Name=TestMethod1 \(1\)"which will run only 1 test where the value is1. -
If you don't escape the parenthesis and try to run
Name=TestMethod1 (1), you will get the following errorIncorrect format for TestCaseFilter Missing Operator '|' or '&'. Specify the correct format and try again. Note that the incorrect format can lead to no test getting executed.because vstest filter system thinks the parenthesis are there to help with OR and AND operators between condition.
Summary seems correct. Is it possible to forward this issue to the VSTest ADO team to update to use the proper escape for the filters they are passing to vstest? Or is this the correct team already?
This is very similar problem: https://github.com/microsoft/azure-pipelines-tasks/issues/13130