Search code examples
seleniumazure-devopsbuild-definition

Exclude Selenium test methods in C# test project using VSTS


I have a Selenium test project which is checked into a VSTS repo and I am trying to create a scheduled build definition in VSTS to run a subset of the test functions contained in the built project assembly "SeleniumTest.dll".

As part of the build definition I have a VS Test task which looks like the following:

enter image description here

In an attempt to exclude all the test classes I do not want run, I have included the following runsettings file.

<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
        <Configuration>
          <CodeCoverage>

            <Functions>  
              <Exclude>  
                <!-- Exclude methods in the SeleniumTests.Tests\ZoneTest: --> 
                <Function>SeleniumTests.Tests\.LoginTest\..*</Function>
                <Function>SeleniumTests.Tests\.ProfileTest\..*</Function>
              </Exclude>  
            </Functions>   

          </CodeCoverage>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

I'm not sure if a runsettings file is the thing I need to achieve this. If not what apporach should be used?


Solution

  • The Visual Studio task include Test Filter criteria setting that can filter tests.

    Allowed operators:

    • = implies an exact match

    • != imples an exact not match

    • ~ implies a contains lookup

    More information: TestCase filter

    BTW, the runsettings file you provided is used for CodeCoverage instead of filter test to run.