简体   繁体   English

Devops Pipeline 拒绝运行 XUnit 测试

[英]Devops Pipeline refusing to run XUnit tests

I have been really getting frustrated with getting unit tests to run in a Azure Devops Pipeline below is my YAML file contents我对让单元测试在 Azure Devops Pipeline 中运行感到非常沮丧,下面是我的 YAML 文件内容

trigger:
- main

pool:
  vmImage: 'windows-2019'

variables:
  solution: '**/FestWise.stock*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  imageRepository: 'festwisestock'
  dotNetCoreVrs: '3.1.x'
  
steps:
- task: UseDotNet@2
  inputs:
    version: '$(dotNetCoreVrs)'
    packageType: 'sdk'


- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: '**/FestWise.stock*.sln'
    feedsToUse: 'select'

- task: DotNetCoreCLI@2
  displayName: 'Restore project dependencies'
  inputs:
    command: 'restore'
    projects: '**/FestWise.Stock/FestWise.Stock.API/FestWise.StockService*.csproj'

- task: DotNetCoreCLI@2
  displayName: 'Build the project - $(buildConfiguration)'
  inputs:
    command: 'build'
    arguments: '--no-restore --configuration $(buildConfiguration)'
    projects: '**/FestWise.Stock/FestWise.Stock.API/FestWise.StockService*.csproj'

- task: DotNetCoreCLI@2
  displayName: 'Run unit tests - $(buildConfiguration)'
  inputs:
    command: 'test'
    arguments: '--no-build --configuration $(buildConfiguration)'
    publishTestResults: true
    projects: '**/*StockService.UnitTests.csproj'

the result is as follows:结果如下:

Starting: Run unit tests - Release
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.187.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
C:\Windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
C:\hostedtoolcache\windows\dotnet\dotnet.exe test D:\a\1\s\FestWise.Stock\FestWise.StockService.UnitTests\FestWise.StockService.UnitTests.csproj --logger trx --results-directory D:\a\_temp --no-build --configuration Release
##[warning]No test result files were found.
Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
Finishing: Run unit tests - Release

This is the furthest that i have come, it states it found the correct project but subsequently doesnt run any tests这是我来的最远的,它说它找到了正确的项目,但随后没有运行任何测试

So this was a drama to get figured out, for some reason it didnt want to find the build sln from the previous step and thus the --no-build argument made it not work所以这是一个需要弄清楚的戏剧,由于某种原因,它不想从上一步中找到构建 sln,因此--no-build参数使它不起作用

removing that argument solved it for me删除那个论点为我解决了它

new complete yaml (with some improvements to make it more variable dependent)新的完整 yaml(进行了一些改进以使其更依赖于变量)

trigger:
- main

pool:
  vmImage: 'windows-2019'

variables:
  solution: '**/FestWise.stock*.sln'
  projectPath: '**/FestWise.Stock/FestWise.Stock.API/FestWise.StockService*.csproj'
  testProjectPath: '**/*/FestWise.StockService.UnitTests.csproj'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
  dotNetCoreVrs: '3.1.x'
  
steps:
- task: UseDotNet@2
  inputs:
    version: '$(dotNetCoreVrs)'
    packageType: 'sdk'


- task: NuGetCommand@2
  inputs:
    command: 'restore'
    restoreSolution: $(solution)
    feedsToUse: 'select'

- task: DotNetCoreCLI@2
  displayName: 'Restore project dependencies'
  inputs:
    command: 'restore'
    projects: $(projectPath)

- task: DotNetCoreCLI@2
  displayName: 'Build the project - $(buildConfiguration)'
  inputs:
    command: 'build'
    arguments: '--no-restore --configuration $(buildConfiguration)'
    projects: $(projectPath)


- task: DotNetCoreCLI@2
  inputs:
      command: "test"
      includeNuGetOrg: true
      projects: $(testProjectPath)
      publishTestResults: true
  displayName: Run the server-side tests

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM