【问题标题】:Filtering xUnit Tests in pipeline AzureDevops在管道 AzureDevops 中筛选 xUnit 测试
【发布时间】:2021-01-03 11:48:46
【问题描述】:

我似乎没有正确过滤,我正在运行我不想运行的测试。

我有

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

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" '
          
          
            

我需要了解我该怎么做

  • 只运行属于 MyProjectA 的测试
  • 只在 MyProjectA 中运行 BBB.Tests

我该怎么做?我需要改变什么?

非常感谢

【问题讨论】:

  • 您可以使用 !**\bin\${{ parameters.buildConfiguration }}\**\MyProjectB.Tests*.dll 之类的否定条件排除 MyProjectB 测试,或者使用 **\bin\${{ parameters.buildConfiguration }}\**\MyProjectA.Tests*.dll 仅包含项目 A。在后一种情况下删除**\bin\${{ parameters.buildConfiguration }}\**\*Tests*.dll
  • @user1672994 感谢您的及时回复。所以你能有 2 个这样的 *\bin\${{ parameters.buildConfiguration }}***Tests.dll !**\bin\${{ parameters.buildConfiguration }}* *MyProjectB.Tests.dll 会不会只运行 MyProjectA.Tests?
  • 是的,它也应该可以。但是,*** 是不正确的。它应该是 ** 或 *。在此处查看模式 -docs.microsoft.com/en-us/azure/devops/pipelines/tasks/…
  • 您好朋友,请检查以下几个答案是否可以解决您的问题。如果您有任何疑问,请随时在此处分享。

标签: c# azure-devops xunit


【解决方案1】:

您可以在引用TestCaseFilterVSTest@2 任务上使用testFiltercriteria 属性

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.

所以在你的情况下它可能是

FullyQualifiedName=~MyProjectA

FullyQualifiedName=~MyProjectA.Tests.BBB

更多过滤详情请看here

【讨论】:

  • @developer9969 如果我的回复对您有帮助,您可以考虑点赞吗?
【解决方案2】:

只运行属于 MyProjectA 的测试

您可以在测试文件中指定项目名称:

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

只在 MyProjectA 中运行 BBB.Tests

您可以使用Test filter criteria 过滤来自 BBB.Tests 的测试:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-29
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    • 2020-12-27
    相关资源
    最近更新 更多