首页 > 解决方案 > Azure Pipeline VSTest@2 Task 认为以“Tester”结尾的项目是测试项目

问题描述

我的 YAML:

# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core

trigger:
- master

pool:
  vmImage: 'windows-latest'


variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
- task: NuGetToolInstaller@1

- task: NuGetCommand@2
  inputs:
    restoreSolution: '$(solution)'

- task: VSBuild@1
  inputs:
    solution: '$(solution)'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" /p:DeployIisAppPath="Default Web Site"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

我有一个名为DatabaseModeler Tester

在此处输入图像描述

当管道运行时,我收到以下错误:

在此处输入图像描述

这个项目不是一个测试项目,也没有任何测试依赖。

标签: c#asp.net-coreazure-devopsazure-pipelines

解决方案


VsTest 任务的默认值为:

        {
            "name": "testAssemblyVer2",
            "type": "multiLine",
            "label": "Test files",
            "defaultValue": "**\\*test*.dll\n!**\\*TestAdapter.dll\n!**\\obj\\**",
            "required": true,
            "helpMarkDown": "Run tests from the specified files.<br>Ordered tests and webtests can be run by specifying the .orderedtest and .webtest files respectively. To run .webtest, Visual Studio 2017 Update 4 or higher is needed. <br><br>The file paths are relative to the search folder. Supports multiple lines of minimatch patterns. [More information](https://aka.ms/minimatchexamples)",
            "groupName": "testSelection",
            "properties": {
                "rows": "3",
                "resizable": "true"
            },
            "visibleRule": "testSelector = testAssemblies"
        },

https://github.com/microsoft/azure-pipelines-tasks/blob/master/Tasks/VsTestV2/task.json#L72

请注意,该任务将拾取名称中包含“test”的任何程序集。

            "defaultValue": "**\\*test*.dll\n!**\\*TestAdapter.dll\n!**\\obj\\**",

在 VsTest2 任务上设置testAssemblyVer2属性将允许您选择正确的测试程序集。

- task: VSTest@2
  inputs:
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    testAssemblyVer2: "**\\*test*.dll\n!**\\*TestAdapter.dll\n!**\\obj\\**\n!**\Tester*.dll",

Tester*.dll在这种情况下,我为:添加了一个特定的排除\n!**\Tester*.dll项,但您也可以创建一个更具体的规则来根据您的解决方案的文件夹结构选择您的测试程序集,例如当您的测试都位于tests文件夹中时:

"**\\tests\\*test*.dll"

推荐阅读