vstest.console.exe with ClassName as /testcasefilter
Asked Answered
S

3

11

I am looking for executing the unit test by ClassName using vstes.console.exe, any help

I tried like

/TestCaseFilter:"ClassName=ProgressTests"

but that throws this error:

Error: No tests matched the filter because it contains one or more properties that are not valid (ClassName). Specify filter expression containing valid properties (TestCategory, Priority, FullyQualifiedName, Name) and try again.

Thanks

Spy answered 23/8, 2016 at 8:8 Comment(0)
M
14

You can run the tests by specifying the fully qualified class name:

vstest.console MyBusinessDomain.Tests.dll /testcasefilter:FullyQualifiedName~MyBusinessDomain.Tests.Shopping.Cart

where:

MyBusinessDomain.Tests.dll is the test dll

MyBusinessDomain.Tests.Shopping.Cart is the fully qualified class name

Or you can run the tests classes by namespace:

vstest.console MyBusinessDomain.Tests.dll /testcasefilter:FullyQualifiedName~MyBusinessDomain.Tests.Shopping

This command will run all the tests under MyBusinessDomain.Tests.Shopping namespace.

NOTE: FYI, vstest.console is newer than mstest and is preferred for running via the command line. It can be added to the environment path with this location(for VS2015) :

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow
Mucro answered 3/2, 2017 at 15:13 Comment(3)
In Visual Studio 2019 I just tried vstest path/to/tests.dll /testcasefilter:"ClassName=SomeTestClass" and it worked just fine. Maybe this support was added back in VS 2019?Rainproof
Actually it was /testcasefilter:ClassName~SomeTestClass (~ not =)Rainproof
Is there away to specify the sequential order in which tests should run?Operant
T
5

According to https://blogs.msdn.microsoft.com/vikramagrawal/2012/07/23/running-selective-unit-tests-in-vs-2012-rc-using-testcasefilter/ - "ClassName is only valid for unit tests for Windows store apps, currently not available for classic MSTest" although that blog post is from years ago now though.

You could just use the FullyQualifiedName filter type as in /testcasefilter:FullyQualifiedName~NameSpace.Class

Tubercle answered 20/9, 2016 at 15:20 Comment(0)
E
2

The tilda ~ means "contains", so if Foobar is the name of your class:

vstest.console bin\Debug\MyTests.dll /TestCaseFilter:FullyQualifiedName~Foobar

See https://msdn.microsoft.com/en-us/library/jj155800.aspx

Epigynous answered 18/1, 2018 at 2:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.