【问题标题】:Azure Dev Ops test step not finding tests (.net 5)Azure Devops 测试步骤未找到测试 (.net 5)
【发布时间】:2021-03-26 03:16:25
【问题描述】:

我有一个简单的 .net 5 项目,其中包含一个主项目和一个带有 nUnit3 测试的单元测试项目。在我的机器上(带有 Visual Studio for mac fwiw 的 mac)测试在构建时发现并按预期工作。

当我尝试在 Azure 开发操作中设置构建管道时,没有发现我的任何测试,并且我在日志中看到以下行:

Test run detected DLL(s) which were built for different framework and platform versions. Following DLL(s) do not match current settings, which are .NETFramework,Version=v4.0 framework and X86 platform.

GenericRepositoryTests.dll is built for Framework .NETCoreApp,Version=v5.0 and Platform AnyCPU.
Microsoft.TestPlatform.CommunicationUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.

它报告了更多 Microsoft dll,但您明白了。这是我的构建过程的 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:
# Added this step manually
- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 5.0.100'
  inputs:
    packageType: 'sdk'
    version: '5.0.100'
    includePreviewVersions: true
# Added this step manually
- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/*.csproj'
- 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:
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
      **\*test*.dll
      !**\*TestAdapter.dll
      !**\obj\**
    searchFolder: '$(System.DefaultWorkingDirectory)'
    codeCoverageEnabled: true

如何确保将 Azure Dev Ops 测试运行器设置设置为运行 .net 5 dll?

谢谢

【问题讨论】:

  • 尝试运行 'dotnet test'。
  • @jessehouwing 成功了,谢谢!

标签: azure-devops nunit .net-5


【解决方案1】:

感谢jessehouwing 我发现我需要的答案是使用 dotnet test 而不是 VSTest:

这是我的最终管道:

trigger:
- main

pool:
  vmImage: 'windows-latest'

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

steps:

- task: UseDotNet@2
  displayName: 'Use .NET Core sdk 5.0.100'
  inputs:
    packageType: 'sdk'
    version: '5.0.100'
    includePreviewVersions: true

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    command: 'build'
    projects: '**/*.sln'

- task: DotNetCoreCLI@2
  displayName: 'dotnet test'
  inputs:
    command: 'test'
    projects: '**/*tests.csproj'
    arguments: '--configuration $(buildConfiguration) --collect "Code coverage"'
    testRunTitle: 'Generic Repository Tests'

【讨论】:

  • 您好,感谢您的分享,您可以Accept it as an Answer,它可以帮助遇到相同问题的其他社区成员,谢谢。
【解决方案2】:

请尝试安装NUnit3TestAdapter<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />,然后查看结果。

有关更多解决方法,请参阅:TFS Tests do not match framework settings。

【讨论】:

  • 当我遇到这个问题时,我已经在使用那个版本的 nUnit 测试适配器了。使用 dotnet CLI 而不是 VSTest 运行器进行测试已经为我解决了问题(正如 jessehouwing 在我的问题评论中所建议的那样)
  • 很高兴听到 dotnet 测试可以解决这个问题,并感谢您在这里分享。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-25
  • 1970-01-01
  • 2020-05-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多