gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 20:28:19 25 4
gpt4 key购买 nike

目前,我正在尝试为我们的解决方案设置一个新管道,但无法让 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\**.

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

最佳答案

尝试这个:

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

关于azure-devops - 如何在 AzureDevOps Pipeline VSTest@2 中定义多个匹配模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56166045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com