简体   繁体   中英

Filtering xUnit Tests in pipeline AzureDevops

I dont seem to be getting the filtering right and I am running tests I dont want to run.

I have

      MySolution  (Solution)
        MyProjectA.Tests
            AAA.Tests
            BBB.Tests
        MyProjectB.Tests
            AAA.Tests               
            

Task in devops

      - task: VSTest@2
        displayName: 'VsTest - testAssemblies'
        inputs:    
          testAssemblyVer2: |
            **\bin\${{ parameters.buildConfiguration }}\**\*Tests*.dll           
            !**\obj\**
            !**\xunit.runner.visualstudio.testadapter.dll
            !**\xunit.runner.visualstudio.dotnetcore.testadapter.dll
          platform: '${{ parameters.buildPlatform }}'
          configuration: '${{ parameters.buildConfiguration }}'
          searchFolder: '$(System.DefaultWorkingDirectory)'        
          otherConsoleOptions: '/platform:x64 /Framework:.NETCoreApp,Version=v3.1 /logger:console;verbosity="normal" '
          
          
            

I need to understand how I can

  • run only tests belonging to MyProjectA
  • run just BBB.Tests in MyProjectA

How do I do that? what do I need to change?

Many thanks

You can use testFiltercriteria property on VSTest@2 task which refer to TestCaseFilter

在此处输入图像描述

Run tests that match the given expression.

<Expression> is of the format <property>=<value>[|<Expression>].

Example: /TestCaseFilter:"Priority=1"

Example: /TestCaseFilter:"TestCategory=Nightly|FullyQualifiedName=Namespace.ClassName.MethodName" Warning: The /TestCaseFilter command line option cannot be used with the /Tests command line option.

For information about creating and using expressions, see TestCase filter.

So in you case it could be

FullyQualifiedName=~MyProjectA

and

FullyQualifiedName=~MyProjectA.Tests.BBB

For more details about filtering pleace take a look here

run only tests belonging to MyProjectA

You could specify the project name in the test files:

- task: VSTest@2
        displayName: 'VsTest - testAssemblies'
        inputs:    
          testAssemblyVer2: |
            **\MyProjectA.Tests\bin\${{ parameters.buildConfiguration }}\**\*Tests*.dll           
            !**\obj\**
            ...
      

run just BBB.Tests in MyProjectA

You could use the Test filter criteria to filter the tests from BBB.Tests:

- task: VSTest@2
        displayName: 'VsTest - testAssemblies'
        inputs:    
          testAssemblyVer2: |
            **\MyProjectA.Tests\bin\${{ parameters.buildConfiguration }}\**\*Tests*.dll           
            !**\obj\**
            testFiltercriteria: 'TestCategory=BBB'
            ...
      

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM