首页 > 解决方案 > 无法使用 Azure 在 YAML 中运行自动化测试

问题描述

我正在尝试运行一些自动化测试作为构建管道的一部分,但我一直没有返回任何结果。我的测试文件通常看起来像“ApiTests”或“UITests”。我试图通过查找文件的“测试”部分来定位它们。但是,我在自动化测试运行程序中不断收到此消息:测试运行检测到为不同框架和平台版本构建的 DLL。以下 DLL(s) 与当前设置不匹配,即 .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 找不到我要的文件。但我担心它会阻止测试实际运行。VSTest 任务的输出如下:共有 1 个测试文件与指定的模式匹配。但后来它说:Publishing test results: 0 然后运行后的 Tests 选项卡没有结果,也没有运行测试

标签: c#azureautomationyamlazure-pipelines

解决方案


现在我遇到了这个问题:##[警告]没有找到与给定过滤器匹配的测试源' **test .dll,!测试适配器.dll,!\obj *'

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

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

文件夹结构

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

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

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

有关详细信息,请参阅运行 xUnit 测试。


推荐阅读