Reputation: 4750
If there is more information needed, let me know in the comments.
Automated testing is supposedly supported fairly readily in Azure DevOps, by way of adding one or more tasks to your pipeline, which can be triggered after pushing new commits and having your software built automatically. With Visual Studio, this would generally take the form of DevOps building your Visual Studio solution, then running one or more test projects that are, more than likely, a part of that solution.
My problem is this: There does not seem to be one, single example of how to actually do this. And when I try, I get this error:
This task is supported only on Windows agents and cannot be used on other platforms.
This is after adding the Visual Studio Test task. When using a minimal pipeline, the solution is able to build fine, and the pipeline runs correctly. When adding a very, very basic task to run the unit tests, the error message above is returned.
I have tried searching around for clear instructions or examples of how to set this up, and I have tried searching for that particular error. What results do come up are simply not very informative.
Because clear instructions don't exist elsewhere, I will ask on SO: What are the basic, but clear steps needed to set up an Azure DevOps pipeline which will build a Visual Studio solution which uses .NET Core, then run the test project(s) inside?
Upvotes: 2
Views: 1978
Reputation: 1906
Visual Studio Test task is required to be run on Windows. Take a look at the example - in pool:vmImage: ubuntuLatest
I am specifying to get a concrete machine to run all my steps inside. See the list of default machines hosted by Microsoft. For instance, you can use windows-latest
to have your Visual Studio Test step run properly.
However, Azure DevOps introduced a new set of dotnet core CLI tasks to build and test .net core applications (Windows is not required to perform them).
I found really nice description from Scott Hanselman's blog. It would build, test, and publish your solution with .net core projects.
trigger:
- main
pool:
vmImage: 'ubuntu-latest'
variables:
buildConfiguration: 'Release'
steps:
- task: UseDotNet@2
displayName: ".NET Core 3.1.x"
inputs:
version: '3.1.x'
packageType: sdk
- script: dotnet build --configuration $(buildConfiguration)
displayName: 'dotnet build $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: "Test"
inputs:
command: test
projects: '**/*tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
- task: DotNetCoreCLI@2
displayName: "Publish"
inputs:
command: 'publish'
publishWebProjects: true
arguments: '-r linux-x64 --configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
- task: PublishBuildArtifacts@1
displayName: "Upload Artifacts"
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'hanselminutes'
Later you can play with official MSDN documentation to add code coverage, test results, etc.
Upvotes: 3