Search code examples
azure-pipelinesvstest

How do I specify a set of tests using VSTest in a Pipeline


Using azure pipelines I want to build and run web service tests. Using the classic pipeline builder (so not the YAML) I want to be able to select a specific set of tests to run. My tests are grouped into various classes. Each class has numerous tests.

If I leave the filter field empty I will run all tests in all classes. But I would like to specify a class of tests. How do I do this?

I have tried the following but no tests can be found

ClassName=WebServices.SocialTests

ClassName=SocialTests

Tests=SocialTests

or

Tests=WebServices.SocialTests

Using Jenkins, I can run these tests from the command line. All I have to do is specify the following:

dotnet vstest mytests.dll /Tests:SocialTests

So the question is why can i not do it in a pipeline?


Solution

  • As workaround , you can add TestCategory to the test method , for example: --filter TestCategory=CategoryA , runs tests which are annotated with [TestCategory("CategoryA")].

    namespace MSTestNamespace
    {
        using Microsoft.VisualStudio.TestTools.UnitTesting;
    
        [TestClass]
        public class UnitTestClass1
        {
            [Priority(2)]
            [TestMethod]
            public void TestMethod1(){
            
            }
    
            [TestCategory("CategoryA")]
            [Priority(3)]
            [TestMethod]
            public void TestMethod2(){
            }
        }
    }
    

    For details , please refer to this document.