【问题标题】:How to define multiple matching patterns in AzureDevOps Pipeline VSTest@2?如何在 AzureDevOps Pipeline VSTest@2 中定义多个匹配模式?
【发布时间】:2019-10-03 14:00:37
【问题描述】:

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

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

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

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

 ...
 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...

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

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

    testAssemblyVer2: '**\*test*.dll
      !**\*TestAdapter.dll
      !**\obj\**'

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

...
 Test assemblies : **\*test*.dll !**\*TestAdapter.dll !**\obj\**
...
 ##[warning]No test assemblies found matching the pattern: **\*test*.dll,!**\*TestAdapter.dll,!**\obj\**.

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

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

    testAssemblyVer2: '**\*test*.dll,!**\*TestAdapter.dll,!**\obj\**'

输出:

 ...
 Test assemblies : **\*test*.dll,!**\*TestAdapter.dll,!**\obj\**
 ...
 ##[warning]No test assemblies found matching the pattern: **\*test*.dll,!**\*TestAdapter.dll,!**\obj\**.

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

所以在第四种情况下,我从the documentation 中取值

testAssemblyVer2: '**\*test*.dll!**\*TestAdapter.dll!**\obj\**'

但它也失败并出现类似的错误消息:

...
Test assemblies : **\*test*.dll!**\*TestAdapter.dll!**\obj\**
...
##[warning]No test assemblies found matching the pattern: **\*test*.dll!**\*TestAdapter.dll!**\obj\**.

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

【问题讨论】:

    标签: azure-devops azure-pipelines vstest


    【解决方案1】:

    试试这个:

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

    【讨论】:

    • 是的,这行得通。如果第一个模式与属性名称在同一行,则似乎存在错误。微软也应该为此采用文档。
    • 是的,它看起来像一个错误。感谢您的报告!
    • 谢谢,这帮助我弄清楚了为什么找不到我的测试程序集。 MS 需要更好的文档或示例。
    猜你喜欢
    • 2023-01-08
    • 2015-09-10
    • 2023-03-23
    • 1970-01-01
    • 2011-11-04
    • 1970-01-01
    • 1970-01-01
    • 2022-06-10
    • 2011-10-20
    相关资源
    最近更新 更多