如何在 AzureDevOps Pipeline VSTest@2 中定义多个匹配模式?

Oli*_*ver 6 vstest azure-devops azure-pipelines

目前,我正在尝试为我们的解决方案设置一个新管道,但无法让 Visual Studio 测试在我的解决方案中找到正确的测试集。它要么选择一个不包含任何测试的 DLL(这会导致任务失败),要么如果我指定了该testAssemblyVer2属性,它会产生一个警告,提示它找不到任何要测试的程序集。

我们正在使用的基本任务配置:

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    searchFolder: '$(System.DefaultWorkingDirectory)'
    runInParallel: true
    codeCoverageEnabled: true
    diagnosticsEnabled: true
Run Code Online (Sandbox Code Playgroud)

如果我们运行它,我们可以在输出中看到以下配置(部分):

 ...
 Test assemblies : **\*test*.dll,!**\*TestAdapter.dll,!**\obj\**
 ...
 ======================================================
 [command]"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" @d:\a\_temp\66884a11-77b3-11e9-b7cb-25533524cce5.txt
 Microsoft (R) Test Execution Command Line Tool Version 16.0.1
 Copyright (c) Microsoft Corporation.  All rights reserved.

 "d:\a\1\s\Tests\Api\FirstController.Tests\bin\Release\netcoreapp2.1\FirstController.Tests.dll"
 "d:\a\1\s\Tests\Api\SecondController.Tests\bin\Release\netcoreapp2.1\SecondController.Tests.dll"
 "d:\a\1\s\Tests\CreateTranslateStringsFromDeviceConfigurationSettings\bin\Release\netcoreapp2.1\CreateTranslateStringsFromDeviceConfigurationSettings.dll"
 "d:\a\1\s\Tests\Api\FourthController.Tests\bin\Release\netcoreapp2.1\FourthController.Tests.dll"
 "d:\a\1\s\Tests\Api\FifthController.Tests\bin\Release\netcoreapp2.1\FifthController.Tests.dll"
 /Settings:"d:\a\_temp\69a604d0-77b3-11e9-b7cb-25533524cce5.runsettings"
 /EnableCodeCoverage
 /logger:"trx"
 /TestAdapterPath:"d:\a\1\s"
 Starting test execution, please wait...
Run Code Online (Sandbox Code Playgroud)

如您所见,有一个程序集CreateTranslateStringsFromDeviceConfigurationSettings不包含任何测试,但被选为测试的候选对象。我从我的具体解决方案中取了确切的原始名称,只是为了表明它显然与模式不匹配但被选中。现在我们尝试通过定义我们自己的匹配模式来避免这个问题。

如果我们通过助手创建任务,它会默认添加以下值:

    testAssemblyVer2: '**\*test*.dll
      !**\*TestAdapter.dll
      !**\obj\**'
Run Code Online (Sandbox Code Playgroud)

如果我们运行它,我们会得到以下输出:

...
 Test assemblies : **\*test*.dll !**\*TestAdapter.dll !**\obj\**
...
 ##[warning]No test assemblies found matching the pattern: **\*test*.dll,!**\*TestAdapter.dll,!**\obj\**.
Run Code Online (Sandbox Code Playgroud)

在输出中,您可以看到,测试程序集列表不是逗号分隔的,这表明该值未被正确理解,因此可能导致空列表。

因此,我们尝试简单地从第一个运行输出中复制并粘贴逗号值,这会产生以下配置和(失败的)输出:

    testAssemblyVer2: '**\*test*.dll,!**\*TestAdapter.dll,!**\obj\**'
Run Code Online (Sandbox Code Playgroud)

输出:

 ...
 Test assemblies : **\*test*.dll,!**\*TestAdapter.dll,!**\obj\**
 ...
 ##[warning]No test assemblies found matching the pattern: **\*test*.dll,!**\*TestAdapter.dll,!**\obj\**.
Run Code Online (Sandbox Code Playgroud)

现在输出与第一个匹配,但它仍然不起作用。所以使用逗号似乎不是要走的路。

因此,在第四个案例是我从价值的文件

testAssemblyVer2: '**\*test*.dll!**\*TestAdapter.dll!**\obj\**'
Run Code Online (Sandbox Code Playgroud)

但它也因类似的错误消息而失败:

...
Test assemblies : **\*test*.dll!**\*TestAdapter.dll!**\obj\**
...
##[warning]No test assemblies found matching the pattern: **\*test*.dll!**\*TestAdapter.dll!**\obj\**.
Run Code Online (Sandbox Code Playgroud)

那么如何以正确的方式定义多个模式呢?

Sha*_*zyk 9

尝试这个:

- task: VSTest@2
  inputs:
    testAssemblyVer2: |
     **\*test.dll
     !**\*TestAdapter.dll
     !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
Run Code Online (Sandbox Code Playgroud)