无法使用 Azure 在 YAML 中对 运行 进行自动化测试

Cannot Get Automated Tests to Run in YAML using Azure

我正在尝试 运行 一些自动化测试作为构建管道的一部分,但我一直没有返回任何结果。我的测试文件通常看起来像“ApiTests”或“UITests”。我试图通过查找文件的“测试”部分来定位它们。但是,我在自动化测试 运行ner 中不断收到此消息:测试 运行 检测到为不同框架和平台版本构建的 DLL。以下 DLL 与当前设置不匹配,即 .NETFramework、Version=v4.0 框架和 X86 平台。 根据 csproj 文件,我的版本是 3.1。 这是 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:
- main

pool:
  vmImage: 'windows-latest'

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

steps:
- task: NuGetToolInstaller@1

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

- task: UseDotNet@2
  displayName: 'Install .NET Core SDK'
  inputs:
    version: 3.0.x
    performMultiLevelLookup: true
- 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)'
    msbuildArchitecture: 'x64'

- task: VSTest@2
  displayName: 'Automated Tests' 
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*test*.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
    testFiltercriteria: '/Tests:Tests'
    uiTests: true
    runTestsInIsolation: true
    codeCoverageEnabled: true
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

我的文件通常命名为:AppsSigninTests.cs

我的实际测试是这样的:

[Fact]
        public void SomethingSomethingSomething()
        {
            //Test Code Here
        }

我应该在测试标题的末尾添加“测试”吗?我错过了什么让 YAML 错过了这些测试?

编辑 我现在已经到了找到文件但没有 运行 实际测试的地步(仍然没有显示结果)。现在是 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:
- main

pool:
  vmImage: 'windows-latest'

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

steps:
- task: NuGetToolInstaller@1

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

#- task: UseDotNet@2
  #displayName: 'Install .NET Core SDK'
  #inputs:
    #version: 3.0.x
    #performMultiLevelLookup: true

- 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
  displayName: 'Automated Tests' 
  inputs:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      AutomatedRegression.csproj
      !**\*TestAdapter.dll
      !**\obj\**
#**\*test*.dll
    searchFolder: '$(System.DefaultWorkingDirectory)'
    testFiltercriteria: '/Tests:VerySpecificNameOfTest'
    uiTests: true
    runTestsInIsolation: true
    codeCoverageEnabled: true
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

test.dll 行似乎成功了,所以 yaml 找不到我要查找的文件。但我担心它会阻止测试实际上 运行ning。 VSTest 任务的输出是这样的:共有 1 个测试文件与指定的模式匹配。 但后来它说:发布测试结果:0 然后 运行 之后的测试选项卡没有结果,也没有测试 运行

Now I am getting this issue: ##[warning]No test sources found matching the given filter '**test.dll,!TestAdapter.dll,!\obj*'

“旧”.NET 的文件位于 Release 文件夹中(由 BuildConfiguration 变量描述)。

.NET Core 构建包含一个额外的文件夹:

YourNamespaceHere.Tests > bin > Release > netcoreapp2.1 > dll's

当您添加额外的通配符时,构建将找到测试 dll。

**$(BuildConfiguration)\*\*test.dll

详情请参考Running xUnit Tests