How to add a unit test in Azure DevOps pipeline - azure-devops

The build runs well but can not see the unit test result When added a build pipeline which used a classic edit or for my solution.
And the code coverage also blank. I have two projects and tests project in the solution. The unit test task returns the result as below:
A total of 14 test files matched the specified pattern.
No test is available in d:\a\1\s\src.net...
Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Results File: d:\a\_temp\TestResults\VssAdministrator_fv-az686_2019-12-26_06_10_28.trx
Attachments:
d:\a\_temp\TestResults\d301a26b-d99f-4b4e-bbe8-c95e588ee1c5\VssAdministrator_fv-az686 2019-12-26 06_10_20.coverage
Vstest.console.exe exited with code 0.
**************** Completed test execution *********************
Test results files: d:\a\_temp\TestResults\VssAdministrator_fv-az686_2019-12-26_06_10_28.trx
No Result Found to Publish 'd:\a\_temp\TestResults\VssAdministrator_fv-az686_2019-12-26_06_10_28.trx'.
Created test run: 1006840
Publishing test results: 0
Publishing test results to test run '1006840'.
TestResults To Publish 0, Test run id:1006840
Published test results: 0
Publishing Attachments: 2
Completed TestExecution Model...
And also I can not see anymore from the Tests windows.
The test YAML script as below:
steps:
- task: VSTest#2
displayName: 'Test Assemblies'
inputs:
testAssemblyVer2: |
**\$(BuildConfiguration)\*test*.dll
!**\obj\**
codeCoverageEnabled: true
platform: '$(BuildPlatform)'
configuration: '$(BuildConfiguration)'

There no any problem on your YAML, the same definition is all work for me.
A total of 14 test files matched the specified pattern.
No test is available in d:\a\1\s\src.net...
Based on these error message, the test files has been identified out from the folder which means the dlls has exists now. But it still say there's no test available, this is more relative with vstest.console.exe did not identify the test.
For example, if your test project type is NUnit, you could use one extension names NUnit test adapter to support this test type running in visual studio.
But, when the project is published into VSTS, this extension could not be published also, and this extension does not exists in VSTS hosted agent. Without this extension support, the vstest.console.exe could not identify the Nunit test, then it will prompt the message like No test is available in xxxxxxx. See this as refer to.
But, you can installed nuget packages to replace the role of that VS extension.
If it's type is Nunit test, you must ensure add the reference on packages NUnit and NUnit3TestAdapter in your csproj file:
<PackageReference Include="NUnit">
<Version>3.12.0</Version>
</PackageReference>
<PackageReference Include="NUnit3TestAdapter">
<Version>3.15.1</Version>
</PackageReference>
Similar method tp xUnit test.

Related

Run NUnit tests in Azure DevOps pipeline

Is it possible? (It seems not. Does it not support NUnit? What should I use instead?)
Here is my test project.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<IsTestProject>true</IsTestProject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\TheProjectToBeTested\TheProjectToBeTested.csproj" />
</ItemGroup>
</Project>
And here is my azure-pipelines.yml
pool: 'TFSBuild'
variables:
# The web app will not build because it is netcore3.1 and the server only supports netcore3.0.
solution: '**/*Build.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
steps:
- task: NuGetToolInstaller#0
- 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)'
# I added this and I don't undertand it.
- task: VSTest#2
inputs:
testSelector: 'testAssemblies'
testAssemblyVer2: |
**\$(BuildConfiguration)\*test*.dll
**\$(BuildConfiguration)\**\*test*.dll
!**\*Microsoft.VisualStudio.TestPlatform*
!**\obj\**
searchFolder: '$(System.DefaultWorkingDirectory)'
However the tests don't get run.
##[section]Starting: VSTest
==============================================================================
Task : Visual Studio Test
Description : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test (VsTest) runner. Test frameworks that have a Visual Studio test adapter such as MsTest, xUnit, NUnit, Chutzpah (for JavaScript tests using QUnit, Mocha and Jasmine), etc. can be run. Tests can be distributed on multiple agents using this task (version 2).
Version : 2.153.9
Author : Microsoft Corporation
Help : https://learn.microsoft.com/azure/devops/pipelines/tasks/test/vstest
==============================================================================
SystemVssConnection exists true
SystemVssConnection exists true
SystemVssConnection exists true
Running tests using vstest.console.exe runner.
======================================================
Test selector : Test assemblies
Test filter criteria : null
Search folder : E:\TFS\8\s
VisualStudio version selected for test execution : latest
Attempting to find vstest.console from a visual studio installation.
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : false
SystemVssConnection exists true
Run the tests locally using vstest.console.exe
========================================================
Test selector : Test assemblies
Test assemblies : **\Release\*test*.dll,**\Release\**\*test*.dll,!**\*Microsoft.VisualStudio.TestPlatform*,!**\obj\**
Test filter criteria : null
Search folder : E:\TFS\8\s
Run settings file : E:\TFS\8\s
Run in parallel : false
Run in isolation : false
Path to custom adapters : null
Other console options : null
Code coverage enabled : false
Diagnostics enabled : false
Rerun failed tests: false
VisualStudio version selected for test execution : latest
Attempting to find vstest.console from a visual studio installation.
========================================================
======================================================
[command]"E:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform\vstest.console.exe" #E:\TFS\_temp\126341f1-33c9-11eb-a545-b3a68600e11b.txt
Microsoft (R) Test Execution Command Line Tool Version 16.3.0-preview-20190715-02
Copyright (c) Microsoft Corporation. All rights reserved.
vstest.console.exe
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\TheProjectToBeTested.Test.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.CommunicationUtilities.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.CoreUtilities.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.CrossPlatEngine.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.PlatformAbstractions.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.Utilities.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\NUnit3.TestAdapter.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\cs\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\cs\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\cs\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\de\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\de\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\de\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\es\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\es\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\es\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\fr\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\fr\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\fr\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\it\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\it\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\it\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ja\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ja\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ja\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ko\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ko\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ko\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pl\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pl\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pl\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pt-BR\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pt-BR\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pt-BR\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ru\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ru\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ru\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\testhost.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\tr\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\tr\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\tr\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hans\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hans\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hans\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hant\Microsoft.TestPlatform.CommunicationUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hant\Microsoft.TestPlatform.CoreUtilities.resources.dll"
"E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hant\Microsoft.TestPlatform.CrossPlatEngine.resources.dll"
/logger:"trx"
/TestAdapterPath:"E:\TFS\8\s"
Starting test execution, please wait...
Test run will use DLL(s) built for framework .NETFramework,Version=v4.0 and platform X86. Following DLL(s) do not match framework/platform settings.
TheProjectToBeTested.Test.dll is built for Framework .NETCoreApp,Version=v3.0 and Platform AnyCPU.
Microsoft.TestPlatform.CommunicationUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.TestPlatform.CoreUtilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.TestPlatform.CrossPlatEngine.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
Microsoft.TestPlatform.PlatformAbstractions.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
Microsoft.TestPlatform.Utilities.dll is built for Framework .NETStandard,Version=v2.0 and Platform AnyCPU.
NUnit3.TestAdapter.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
testhost.dll is built for Framework .NETCoreApp,Version=v2.1 and Platform AnyCPU.
Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.
No test is available in E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\TheProjectToBeTested.Test.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.CommunicationUtilities.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.CoreUtilities.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.CrossPlatEngine.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.PlatformAbstractions.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\Microsoft.TestPlatform.Utilities.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\NUnit3.TestAdapter.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\cs\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\cs\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\cs\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\de\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\de\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\de\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\es\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\es\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\es\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\fr\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\fr\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\fr\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\it\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\it\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\it\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ja\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ja\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ja\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ko\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ko\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ko\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pl\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pl\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pl\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pt-BR\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pt-BR\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\pt-BR\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ru\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ru\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\ru\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\testhost.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\tr\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\tr\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\tr\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hans\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hans\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hans\Microsoft.TestPlatform.CrossPlatEngine.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hant\Microsoft.TestPlatform.CommunicationUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hant\Microsoft.TestPlatform.CoreUtilities.resources.dll E:\TFS\8\s\TheProjectToBeTested.Test\bin\Release\netcoreapp3.0\zh-Hant\Microsoft.TestPlatform.CrossPlatEngine.resources.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
Results File: E:\TFS\8\s\TestResults\TFSBUILD$_TFSBUILD_2020-12-01_11_33_48.trx
No Result Found to Publish 'E:\TFS\8\s\TestResults\TFSBUILD$_TFSBUILD_2020-12-01_11_33_48.trx'.
##[section]Async Command Start: Publish test results
##[section]Async Command End: Publish test results
##[section]Finishing: VSTest
Please move rather to dotnet command and instead of using VSTest run it using this:
If you have test projects in your repository, then use the .NET Core task to run unit tests by using testing frameworks like MSTest, xUnit, and NUnit.
steps:
# ...
# do this after other tasks such as building
- task: DotNetCoreCLI#2
inputs:
command: test
projects: '**/*Tests/*.csproj'
arguments: '--configuration $(buildConfiguration)'
Run NUnit tests in Azure DevOps pipeline
To test .Net Core dlls with Visual Studio Test task, please try to add following additional settings of Visual Studio Test task:
Path to vstest.console.exe: E:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\Common7\IDE\Extensions\TestPlatform.
Other console options: /framework:".NETCoreApp,Version=v3.0":
You maybe missing NUnit3TestAdapter package in one of project
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.10.1" targetFramework="net45" />
<package id="NUnit3TestAdapter" version="4.1.0" targetFramework="net45" />
</packages>
After adding package this task was running all nunit tests
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
If you have a .net core application as you do, the other answer using DotNetCoreCLI#2 with test command is the correct answer.
However, if you are using framework and don't want to use VSTest or really have to use nunit there is another way to get this to work.
You can use the pipeline with a docker container that has nunit in. You can use the code from here which is a mono image that has nunit added. A requirement of Azure Devops is there is no entry point so you will need to use your own copy without the last line.
Once you have your container you can then run your pipeline in a container
and use a bash command block
- task: Bash#3
inputs:
targetType: 'inline'
script: '/nunit/nunit3-console.exe **/*Tests/*.csproj --configuration $(buildConfiguration)'

Azure Function Build Pipelines Fails when Unit Test Project references the Function project

I am using Visual Studio 2019 Community Edition and I have a multi-tier solution. Below is a screenshot of that.
Please note, it's a sample project to replicate a production solution, so, namings probably are not really important here.
Project specifications: (all netcoreapp3.1)
Sample.AzureFunction.Api - Target Framework: netcoreapp3.1and Azure Function version: 3.0.7
{ Application, Model, ClassLibrary1, and ClassLibrary2 } - Target Framework: netcoreapp3.1 and all are `.netcore class library' projects.
ApiTests - Target Framework: netcoreapp3.1
The Problem
The Azure Build Pipeline fails when there is a reference from the ApiTest project to the Sample.AzureFunction.Api. If I remove the project reference, the build continues to be green. Here is a screenshot from the build errors when the build step is running in the pipeline.
Basically, all the errors are complaining about not finding some dlls. For example, CSC : error CS0006: Metadata file 'D:\a\1\s\publish_output\Application.dll' could not be found [D:\a\1\s\Sample.AzureFunction.Api\Tests\ApiTests\ApiTests.csproj]
Few Notes:
The build step in the pipeline is .net core added automatically by Azure DevOps.
I don't have a dedicated Agent and I use the Azure Pipelines that comes by default when creating a new CI.
Agent specification is windows-2019
I used the classic view to create the pipeline (no YAML) but I could grab the following YAML from the generated steps by clicking on each of them and copying the YAML:
I've spent a day on resolving this issue and I'm running out of ideas now. Any thoughts would be appreciated.
If you remove --output argument your build will succeeded.
It looks like your folder publish_output was cleared before compiling test project. Thus it can't find these dlls there.
Furthermore, you don't need rather to publish as an artifact all dlls. Please use publish command to create artifact for code which is going to be deployed:
- task: DotNetCoreCLI#2
inputs:
command: publish
publishWebProjects: True
arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: True
# this code takes all the files in $(Build.ArtifactStagingDirectory) and uploads them as an artifact of your build.
- task: PublishBuildArtifacts#1
inputs:
pathtoPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'myWebsiteName'
I listed publish_output folder after running your original pipeline and you can find there these files:
Application.deps.json
ClassLibrary1.deps.json
Function1
Sample.AzureFunction.Api.deps.json
bin
host.json

Azure Pipeline Google Tests not running as .EXE

I'm transitioning a traditional C++ code base build to the Azure DevOps Pipeline. We have a bunch of gtest unit tests in a module that is just an executable named "sdktests.exe". It links to gtest 1.8.1. The user has always just manually run this exe and observed the results.
But I can't seem to make it Azure Devops detect and run these tests. I'm guessing that it needs the tests in the form of a DLL that it loads instead of an EXE
Is that the case? Do I need to convert my google tests module from an EXE to a DLL to make this work?
This is my yaml pipeline step
- task: VSTest#2
inputs:
platform: '$(buildPlatform)'
configuration: '$(buildConfiguration)'
testSelector: 'testAssemblies'
testAssemblyVer2: '**\*sdktests*.exe'
This is my Azure build output for the step:
Source filter: **\*sdktests*.exe
SystemVssConnection exists true
d:\a\_tasks\VSTest_ef087383-ee5e-42c7-9a53-ab56c98420f9\2.170.1\Modules\DTAExecutionHost.exe --inputFile d:\a\_temp\input_484b64d0-c544-11ea-bc95-251e50750ee7.json
======================================================
##########################################################################
DtaExecutionHost version 18.170.30112.1.
Starting TestExecution Model...
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
Result Attachments will be stored in LogStore
Result Attachments will be stored in LogStore
Run Attachments will be stored in LogStore
Updated Run Settings:
<RunSettings>
<RunConfiguration>
<BatchSize>1000</BatchSize>
<ResultsDirectory>d:\a\_temp\TestResults</ResultsDirectory>
</RunConfiguration>
</RunSettings>
**************** Starting test execution *********************
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions\TestPlatform\vstest.console.exe "#d:\a\_temp\jcgckxlo13t.tmp"
Microsoft (R) Test Execution Command Line Tool Version 16.6.0
Copyright (c) Microsoft Corporation. All rights reserved.
vstest.console.exe "d:\a\1\s\x64\Release\sdktests.exe"
/Settings:"d:\a\_temp\ktasri4fewz.tmp.runsettings"
/Logger:"trx"
/TestAdapterPath:"d:\a\1\s"
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
No test is available in d:\a\1\s\x64\Release\sdktests.exe. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.
#Joe,
I have run into a similar situation in the past. Here is what I found. If you are running GTest you should be running as you would normally, no need to us VSTest task. The test result file that is generated by GTest is in a JUnit formatted XML file. You can use the publish test results v2 task to publish to the build. The setup would look something like:
- task: CmdLine#1
displayName: Run Unit Tests (GTest)
inputs:
script: 'sdktests.exe'
- task: PublishTestResults#2
displayName: Publish Unit Test Results (GTest)
inputs:
testResultsFiles: '**/SDKTestResults.xml'
testRunTitle: 'GTest Results'
Here are references that you should use to create a solution that meets your needs:
Publish Test Results - Doc
Command Line - Doc

SonarQube/Azure DevOps code analysis failure - .scannerwork/report-task.txt not found

We run automated code-quality scans in SonarQube that are triggered by pipelines in Azure DevOps:
# retrieve and build code, run unit tests etc.
- task: SonarQubePrepare#4
displayName: 'Prepare SonarQube Scan'
inputs:
SonarQube: 'SonarQube DevOps Connection'
scannerMode: 'CLI'
configMode: 'file'
- task: SonarQubeAnalyze#4
displayName: 'Run SonarQube Scan'
- task: SonarQubePublish#4
displayName: 'Publish SonarQube Scan Report'
inputs:
pollingTimeoutSec: '300'
About a week ago, the main analysis task ('Run SonarQube Scan') began failing for all pipelines with the following error:
...
##[error]ERROR: Error during SonarQube Scanner execution
ERROR: Error during SonarQube Scanner execution
##[error]java.lang.IllegalStateException: Unable to load properties from file /home/vsts/work/1/s/.scannerwork/report-task.txt
java.lang.IllegalStateException: Unable to load properties from file /home/vsts/work/1/s/.scannerwork/report-task.txt
...
##[error]Caused by: java.io.FileNotFoundException: /home/vsts/work/1/s/.scannerwork/report-task.txt (No such file or directory)
Caused by: java.io.FileNotFoundException: /home/vsts/work/1/s/.scannerwork/report-task.txt (No such file or directory)
...
We have made no changes to our pipelines, so I am mystified as to what has caused this change.
We are using SonarQube Enterprise EditionVersion 7.9.1 (build 27448) (on-premise installation) and version 4.9.0 of the SonarQube extension for Azure DevOps (published by SonarSource).
UPDATE 25/3/20 (thanks to patricklu-msft):
We are using a Microsoft-hosted build agent with an ubuntu-16.04 image. Running the pipeline in debug mode reveals the following:
2020-03-25T14:25:00.3694399Z 14:25:00.369 DEBUG: Report metadata written to /home/vsts/work/_temp/sonar/20200325.2/eec0f38a-913b-3db3-e1b2-71091ea5f860/report-task.txt
So it appears that the report metadata are being written to /home/vsts/work/_temp/sonar/20200325.2/eec0f38a-913b-3db3-e1b2-71091ea5f860/report-task.txt but SonarQube subsequently looks for them in /home/vsts/work/1/s/.scannerwork/report-task.txt. It looks like there is a mv operation missing somewhere ...
Not sure if it's a SonarQube task side related issue.
According to this link here:
The new version (4.7.x) is looking here:
##[debug]adjustedPattern: 'C:\AzureDevops\Agent2-GCS-Docker\_work\_temp\sonar\199416\**\report-task.txt’
Looks like it's supported to look the report-task.txt in temp folder with new version.
Try to roll back your task version and check if this do the trick.
Closer inspection of the Azure pipelines logs revealed these two entries that weren't there before:
2020-03-26T15:26:44.0989881Z INFO: Executing post-job 'Forbidden Configuration Breaker'
2020-03-26T15:26:44.0990841Z INFO: Executing post-job 'Quality Gate Breaker'
Someone installed the Sonar Build-Breaker Plug-in a week ago without telling us, and none of us have correctly configured it in our pipelines yet. Setting it to skip the quality gate check (sonar.buildbreaker.skip=true) effectively by-passes it (although those two log entries still appear) and the pipelines run successfully once more.
Update 24/04/2020: I have now upgraded the Build Breaker plug-in to v2.3.1 (build 347) and that seems to have fixed the issue.

Code coverage results not being reported after Visual Studio Test step completes successfully

I have a very simple project in my VSTS account with a few tests. I've added a VsTest step to the build and checked the code coverage box. However, after I run the build, it says "no code coverage results available" and suggests that I add a Visual Studio test build step to my build. But when I add one, it's the same as the VsTest step I already have.
How can I get code coverage from my VSTS build?
EDIT: The test logs are below. There were two portions with a lot of special characters I could not copy and paste.
2018-05-04T21:51:59.5221025Z ##[section]Starting: VsTest - testAssemblies
2018-05-04T21:51:59.5227667Z ==============================================================================
2018-05-04T21:51:59.5227804Z Task : Visual Studio Test
2018-05-04T21:51:59.5227968Z Description : Run unit and functional tests (Selenium, Appium, Coded UI test, etc.) using the Visual Studio Test runner. Test frameworks that have a Visual Studio test adapter such as xUnit, NUnit, Chutzpah, etc. can also be run. Tests can be distributed on multiple agents using this task (version 2).
2018-05-04T21:51:59.5228145Z Version : 2.5.8
2018-05-04T21:51:59.5228227Z Author : Microsoft Corporation
2018-05-04T21:51:59.5228339Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkId=835764)
2018-05-04T21:51:59.5228918Z ==============================================================================
2018-05-04T21:52:00.6581473Z Run the tests locally using vstest.console.exe
2018-05-04T21:52:00.6581612Z ========================================================
2018-05-04T21:52:00.6582115Z Test selector : Test assemblies
2018-05-04T21:52:00.6582269Z Test assemblies : **\release\**\*.dll
2018-05-04T21:52:00.6582399Z Test filter criteria : null
2018-05-04T21:52:00.6582534Z Search folder : D:\a\1\s
2018-05-04T21:52:00.6582658Z Run settings file : D:\a\1\s
2018-05-04T21:52:00.6582831Z Run in parallel : false
2018-05-04T21:52:00.6582954Z Run in isolation : false
2018-05-04T21:52:00.6584318Z Path to custom adapters : null
2018-05-04T21:52:00.6584486Z Other console options : null
2018-05-04T21:52:00.6584627Z Code coverage enabled : true
2018-05-04T21:52:00.6584910Z Rerun failed tests: false
2018-05-04T21:52:00.6585116Z VisualStudio version selected for test execution : latest
2018-05-04T21:52:01.5193379Z ========================================================
2018-05-04T21:52:01.5908190Z [command]"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe" #D:\a\_temp\60315131-4fe5-11e8-9269-e9217bdc2ba0.txt
2018-05-04T21:52:06.6551385Z Microsoft (R) Test Execution Command Line Tool Version 15.6.2
2018-05-04T21:52:06.6552014Z Copyright (c) Microsoft Corporation. All rights reserved.
2018-05-04T21:52:06.6552213Z
2018-05-04T21:52:06.8162937Z vstest.console.exe
2018-05-04T21:52:06.8164594Z "D:\a\1\s\TestTesting\TestTesting\bin\Release\net461\Microsoft.VisualStudio.CodeCoverage.Shim.dll"
2018-05-04T21:52:06.8165659Z "D:\a\1\s\TestTesting\TestTesting\bin\Release\net461\TestTesting.dll"
2018-05-04T21:52:06.8166614Z "D:\a\1\s\TestTesting\TestTesting\bin\Release\net461\xunit.abstractions.dll"
2018-05-04T21:52:06.8167552Z "D:\a\1\s\TestTesting\TestTesting\bin\Release\net461\xunit.assert.dll"
2018-05-04T21:52:06.8168335Z "D:\a\1\s\TestTesting\TestTesting\bin\Release\net461\xunit.core.dll"
2018-05-04T21:52:06.8169121Z "D:\a\1\s\TestTesting\TestTesting\bin\Release\net461\xunit.execution.desktop.dll"
2018-05-04T21:52:06.8169879Z "D:\a\1\s\TestTesting\TestTesting\bin\Release\net461\xunit.runner.reporters.net452.dll"
2018-05-04T21:52:06.8170678Z "D:\a\1\s\TestTesting\TestTesting\bin\Release\net461\xunit.runner.utility.net452.dll"
2018-05-04T21:52:06.8171460Z "D:\a\1\s\TestTesting\TestTesting\bin\Release\net461\xunit.runner.visualstudio.testadapter.dll"
2018-05-04T21:52:06.8172221Z "D:\a\1\s\TestTesting\TestTesting\obj\Release\net461\TestTesting.dll"
2018-05-04T21:52:06.8172936Z /EnableCodeCoverage
2018-05-04T21:52:06.8173974Z /logger:"trx"
2018-05-04T21:52:06.8174130Z /TestAdapterPath:"D:\a\1\s"
2018-05-04T21:52:10.5221260Z Starting test execution, please wait...
2018-05-04T21:52:10.9446034Z Test run will use DLL(s) built for framework .NETFramework,Version=v4.6.1 and platform X86. Following DLL(s) do not match framework/platform settings.
2018-05-04T21:52:10.9446506Z xunit.assert.dll is built for Framework 1.1 and Platform AnyCPU.
2018-05-04T21:52:10.9446876Z xunit.core.dll is built for Framework 1.1 and Platform AnyCPU.
2018-05-04T21:52:10.9447201Z xunit.execution.desktop.dll is built for Framework 4.5.2 and Platform AnyCPU.
2018-05-04T21:52:10.9449027Z xunit.runner.reporters.net452.dll is built for Framework 4.5.2 and Platform AnyCPU.
2018-05-04T21:52:10.9449230Z xunit.runner.utility.net452.dll is built for Framework 4.5.2 and Platform AnyCPU.
2018-05-04T21:52:10.9449440Z xunit.runner.visualstudio.testadapter.dll is built for Framework 4.5.2 and Platform AnyCPU.
2018-05-04T21:52:10.9449631Z Go to http://go.microsoft.com/fwlink/?LinkID=236877&clcid=0x409 for more details on managing these settings.
2018-05-04T21:52:10.9449774Z
[[Uncopyable part here. What I could read spelled out "Microsoft Coverage Collection", followed by a copyright.
2018-05-04T21:52:31.9257584Z [xUnit.net 00:00:00.9144322] Discovering: Microsoft.VisualStudio.CodeCoverage.Shim
2018-05-04T21:52:32.0551765Z [xUnit.net 00:00:01.0599884] Discovered: Microsoft.VisualStudio.CodeCoverage.Shim
2018-05-04T21:52:32.4727660Z [xUnit.net 00:00:01.4776210] Discovering: TestTesting
2018-05-04T21:52:32.7346755Z [xUnit.net 00:00:01.7395514] Discovered: TestTesting
2018-05-04T21:52:32.7417690Z [xUnit.net 00:00:01.7468703] Starting: TestTesting
2018-05-04T21:52:33.2084443Z [xUnit.net 00:00:01.9469140] TestTesting.Tests.Skipped [SKIP]
2018-05-04T21:52:33.2085046Z [xUnit.net 00:00:01.9471459] Skipping
2018-05-04T21:52:33.2085275Z [xUnit.net 00:00:01.9542762] Finished: TestTesting
2018-05-04T21:52:33.2881381Z [xUnit.net 00:00:02.2931214] Discovering: xunit.abstractions
2018-05-04T21:52:33.3305957Z [xUnit.net 00:00:02.3357501] Discovered: xunit.abstractions
2018-05-04T21:52:34.0395297Z [xUnit.net 00:00:03.0443103] Discovering: xunit.runner.reporters.net452
2018-05-04T21:52:34.1043673Z [xUnit.net 00:00:03.1090663] Discovered: xunit.runner.reporters.net452
2018-05-04T21:52:34.4684448Z Passed TestTesting.Tests.Passing
2018-05-04T21:52:34.8614665Z Skipped TestTesting.Tests.Skipped
2018-05-04T21:52:34.8620656Z Standard Output Messages:
2018-05-04T21:52:34.8620971Z Skipping
2018-05-04T21:52:34.8625877Z Passed TestTesting.Tests.NoLongerFailing
2018-05-04T21:52:36.1389527Z [xUnit.net 00:00:05.1437439] Discovering: xunit.runner.utility.net452
2018-05-04T21:52:36.2616608Z [xUnit.net 00:00:05.2660797] Discovered: xunit.runner.utility.net452
[[Uncopyable part repeated here.]]
2018-05-04T21:52:38.5800594Z Attachments:
2018-05-04T21:52:38.5800836Z D:\a\1\s\TestResults\b0d720b3-9bb9-4318-bb6b-7bfa8e404a13\VssAdministrator_factoryvm-az384 2018-05-04 21_52_18.coverage
2018-05-04T21:52:38.5801023Z
2018-05-04T21:52:38.5801196Z Total tests: 3. Passed: 2. Failed: 0. Skipped: 1.
2018-05-04T21:52:38.5801368Z Test Run Successful.
2018-05-04T21:52:38.5809597Z Test execution time: 19.0295 Seconds
2018-05-04T21:52:38.6045339Z Results File: D:\a\1\s\TestResults\VssAdministrator_factoryvm-az384_2018-05-04_21_52_34.trx
2018-05-04T21:52:38.9702367Z ##[section]Async Command Start: Publish test results
2018-05-04T21:52:39.1587014Z Publishing test results to test run '3'
2018-05-04T21:52:39.1587207Z Test results remaining: 3. Test run id: 3
2018-05-04T21:52:39.6699238Z Published Test Run : https://wjtesttesting.visualstudio.com/MyFirstProject/_TestManagement/Runs#runId=3&_a=runCharts
2018-05-04T21:52:39.6700510Z ##[section]Async Command End: Publish test results
2018-05-04T21:52:39.6701395Z ##[section]Finishing: VsTest - testAssemblies
[EDIT 2]: Starian Chen asked for the logs with System.Debug set to true. They go over SO's size limit, so I'm linking to them below:
VSTS build log
VSTS test log
EDIT 3: When I specify the framework in "Other console options" of my VsTest build step:
/framework:"Framework461"
It seems to be unhappy with my version. It gives a list of supported frameworks, the highest of which is "Framework45."
Edit 4: I tried a net452 project, with "Framework45". In that case, the tests did run via Starian Chen's instructions here, just substituting "Framework45" for "netcoreapp2.0". However, there was still no code coverage report.
With .Net framework test project, you don’t need to specify framework and vstest.console.exe path in Visual Studio Test task.