#unit-testing #asp.net-core #azure-devops #azure-pipelines #pipeline
Вопрос:
Я действительно расстраивался из-за того, что модульные тесты запускались в конвейере Azure Devops, ниже приведено содержимое моего файла 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'
в результате получается следующее:
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:Windowssystem32chcp.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:hostedtoolcachewindowsdotnetdotnet.exe test D:a1sFestWise.StockFestWise.StockService.UnitTestsFestWise.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
Это самое дальнее, что я сделал, в нем говорится, что он нашел правильный проект, но впоследствии не запускает никаких тестов
Ответ №1:
Так что это была драма, в которой нужно было разобраться, по какой-то причине он не хотел находить sln сборки с предыдущего шага, и поэтому --no-build
аргумент не сработал
удаление этого аргумента решило для меня эту проблему
новый полный 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