testfx icon indicating copy to clipboard operation
testfx copied to clipboard

TestCaseFilter with custom properties?

Open pkrukp opened this issue 4 years ago • 6 comments

Hello,

I'm trying to use TestCaseFilter with custom properties. Is that possible?

I was trying to pass various forms of /TestCaseFilter to vstest.console.exe but without success. Works with TestCategory but not with custom properties.

For example in MSTest:

        [TestProperty("Bug", "12345")]
        [TestMethod]
        public void TestMethod2()

For XUnit it's Trait and for NUnit it's Property.

In https://github.com/Microsoft/vstest-docs/blob/master/docs/filter.md#syntax there's a list of "Supported properties":

  • for MSTest there's no TestProperty there :(
  • for XUnit there's Traits listed but I could not make it work (filter didn't match any test)
  • no NUnit listed

I'm attaching a simple solution with 3 UT projects (mstest, xunit, nunit): ClassLibrary1.zip

I have used vstest.console.exe 16.7.0 from Microsoft.TestPlatform nuget package. (In fact I'd like to pass the TestCaseFilter through RunSettings when vstest is used programmatically through IVsTestConsoleWrapper API, but I have started by checking how it works in the vstest.console.exe - I assume it works the same in API, from microsoft/vstest#2273).

AB#2050968

pkrukp avatar Aug 17 '20 15:08 pkrukp

Looking at the code in MSTest it does not seem to be supported at the moment.

image

For xUnit it works like this: dotnet test --filter Bug=12345 or vstest.console XUnitTestProject1.dll --testcasefilter:Bug=12345.

nohwnd avatar Aug 18 '20 07:08 nohwnd

Looking at the code in MSTest it does not seem to be supported at the moment.

So it must be implemented in each test adapter separately? I was thinking about making this issue a feature request for vstest, but I should probably file it against mstest (and maybe nunit)?

For xUnit it works like this: dotnet test --filter Bug=12345 or vstest.console XUnitTestProject1.dll --testcasefilter:Bug=12345.

Thanks, that way it works.

pkrukp avatar Aug 18 '20 07:08 pkrukp

Yes each test adapter needs to implement it separately because they have different representations of tests. The way this was implemented, there is no common abstraction over this filtering concept. If you want it in MSTest then microsoft/testfx is the repo to search for this issue, or creating a new one. And similarly for NUnit.

nohwnd avatar Aug 19 '20 07:08 nohwnd

@pkruk2 moved your issue to testfx (MSTest), to make it easier for you. No need to file another issue.

Related https://github.com/microsoft/testfx/issues/201

nohwnd avatar Aug 19 '20 07:08 nohwnd

Thank you. I'll try to file FR for other test adapters soon

pkrukp avatar Aug 19 '20 07:08 pkrukp

✅ Successfully linked to Azure Boards work item(s):

testplatform-bot avatar May 03 '24 12:05 testplatform-bot